最近在写一个充值功能,由于不太好测试,各位大佬请看看我这种写法有啥明显逻辑上的bug么,谢谢各位大神
public $data;
public $where;
/**
* aliba回调地址
* {$url}/callback/aliba
**/
public function alibaAction()
{
$this->where = $_GET;
$db = $this->mysql();
switch ($this->where['state']) {
case 2:
$this->data = [
'callback_time' => time(),
'order_type' => 1,
'callback_result' => '充值中',
];
$res = 'no';
break;
case 3:
$this->data = [
'callback_time' => time(),
'status' => 'success',
'order_type' => 3,
];
$res = 'OK';
break;
case 4:
$this->data = [
'callback_time' => time(),
'status' => 'issue_orders',
'order_type' => 2,
'callback_result' => '待补单',
];
$res = 'no';
break;
}
$result = $db->action(function ($database) {
$result = $database->update('cecharge_order', $this->data, [
'order_number' => $this->where['orderid'],
'deletetime' => null,
'order_type' => 1,
'status' => 'wait',
]);
if ($result->rowCount() <= 0) {
dump_log('回调地址: ' . $_SERVER['REQUEST_URI'] . ' 状态: 订单更新失败', 'aliba_callback_error.txt');
return false;
}
if ($this->where['state'] == 2) {
$result = $database->delete('cecharge_info', [
'order_number' => $this->where['orderid'],
]);
if ($result->rowCount() <= 0) {
dump_log('回调地址: ' . $_SERVER['REQUEST_URI'] . ' 状态: 订单记录删除失败', 'aliba_callback_error.txt');
return false;
}
}
dump_log('回调地址: ' . $_SERVER['REQUEST_URI'] . ' 状态: 成功', 'aliba_callback_success.txt');
return false;
});
dump_log('回调地址: ' . $_SERVER['REQUEST_URI'] . '', 'aliba_callback.txt');
return $res;
}
}
`
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…