修改订单接口

This commit is contained in:
Anyon 2020-09-11 10:16:39 +08:00
parent af16caf87a
commit 575e4519b4
2 changed files with 25 additions and 27 deletions

View File

@ -26,7 +26,7 @@ class Notify extends Controller
$notify = ($payment = WechatService::WePayOrder())->getNotify(); $notify = ($payment = WechatService::WePayOrder())->getNotify();
if ($notify['result_code'] == 'SUCCESS' && $notify['return_code'] == 'SUCCESS') { if ($notify['result_code'] == 'SUCCESS' && $notify['return_code'] == 'SUCCESS') {
if ($scene === 'order') { if ($scene === 'order') {
if ($this->setOrder($notify['out_trade_no'], $notify['transaction_id'], $notify['cash_fee'] / 100, 'wxpay')) { if ($this->setOrder($notify['out_trade_no'], $notify['cash_fee'] / 100, $notify['transaction_id'], 'wxpay')) {
return $payment->getNotifySuccessReply(); return $payment->getNotifySuccessReply();
} }
} }
@ -38,15 +38,15 @@ class Notify extends Controller
/** /**
* 订单状态更新 * 订单状态更新
* @param string $code 订单单号 * @param string $code 订单单号
* @param string $payno 交易单号
* @param string $amount 交易金额 * @param string $amount 交易金额
* @param string $paycode 交易单号
* @param string $paytype 支付类型 * @param string $paytype 支付类型
* @return boolean * @return boolean
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
private function setOrder($code, $payno, $amount, $paytype = 'wxpay') private function setOrder($code, $amount, $paycode, $paytype = 'wxpay')
{ {
// 检查订单支付状态 // 检查订单支付状态
$map = ['order_no' => $code, 'payment_status' => 0, 'status' => 2]; $map = ['order_no' => $code, 'payment_status' => 0, 'status' => 2];
@ -55,8 +55,8 @@ class Notify extends Controller
// 更新订单支付状态 // 更新订单支付状态
$this->app->db->name('StoreOrder')->where($map)->update([ $this->app->db->name('StoreOrder')->where($map)->update([
'status' => 3, 'status' => 3,
'payment_no' => $payno,
'payment_type' => $paytype, 'payment_type' => $paytype,
'payment_code' => $paycode,
'payment_status' => 1, 'payment_status' => 1,
'payment_amount' => $amount, 'payment_amount' => $amount,
'payment_remark' => '微信在线支付', 'payment_remark' => '微信在线支付',

View File

@ -199,25 +199,23 @@ class Order extends Auth
public function get() public function get()
{ {
$map = [['mid', '=', $this->mid]]; $map = [['mid', '=', $this->mid]];
if ($this->request->has('order_no', 'post', true)) { if (!$this->request->has('order_no', 'param', true)) {
$map[] = ['order_no', '=', $this->request->post('order_no')]; $map[] = ['status', 'in', [0, 2, 3, 4, 5]];
} else {
$map[] = ['status', 'in', ['0', '2', '3', '4', '5']];
} }
if ($this->request->has('status', 'post', true)) { $query = $this->_query('ShopOrder')->equal('status,order_no');
$map[] = ['status', '=', $this->request->post('status')]; $result = $query->where($map)->order('id desc')->page(true, false, false, 20);
} if (count($result['list']) > 0) {
$result = $this->_query('ShopOrder')->where($map)->order('id desc')->page(true, false, false, 20); $codes = array_unique(array_column($result['list'], 'order_no'));
$codes = array_unique(array_column($result['list'], 'order_no')); $items = $this->app->db->name('ShopOrderItem')->whereIn('order_no', $codes)->select()->toArray();
$glist = $this->app->db->name('ShopOrderList')->whereIn('order_no', $codes)->select()->toArray(); foreach ($result['list'] as &$vo) {
foreach ($result['list'] as &$vo) { [$vo['count'], $vo['items']] = [0, []];
[$vo['goods_count'], $vo['list']] = [0, []]; foreach ($items as $item) if ($vo['order_no'] === $item['order_no']) {
foreach ($glist as $goods) if ($vo['order_no'] === $goods['order_no']) { $vo['items'][] = $item;
$vo['list'][] = $goods; $vo['count'] += $item['stock_sales'];
$vo['goods_count'] += $goods['number_goods']; }
} }
} }
$this->success('获取订单列表成功!', $result); $this->success('获取订单数据成功!', $result);
} }
/** /**
@ -228,15 +226,15 @@ class Order extends Auth
*/ */
public function cancel() public function cancel()
{ {
$map = $this->_vali(['mid' => $this->mid, 'order_no.require' => '订单号不能为空!']); $map = $this->_vali(['order_no.require' => '订单号不能为空!']);
$order = $this->app->db->name('ShopOrder')->where($map)->find(); $order = $this->app->db->name('ShopOrder')->where(['mid' => $this->mid])->where($map)->find();
if (empty($order)) $this->error('订单查询失败,请稍候再试!'); if (empty($order)) $this->error('订单查询失败,请稍候再试!');
if (in_array($order['status'], [1, 2])) { if (in_array($order['status'], [1, 2])) {
$result = $this->app->db->name('ShopOrder')->where($map)->update([ $result = $this->app->db->name('ShopOrder')->where($map)->update([
'status' => 0, 'status' => 0,
'cancel_state' => 1, 'cancel_status' => 1,
'cancel_stime' => date('Y-m-d H:i:s'), 'cancel_remark' => '用户主动取消订单!',
'cancel_remark' => '用户主动取消订单!', 'cancel_datetime' => date('Y-m-d H:i:s'),
]); ]);
if ($result !== false && OrderService::instance()->syncStock($order['order_no'])) { if ($result !== false && OrderService::instance()->syncStock($order['order_no'])) {
$this->success('订单取消成功!'); $this->success('订单取消成功!');
@ -338,7 +336,7 @@ class Order extends Auth
$map = $this->_vali(['order_no.require' => '订单编号不能为空!']); $map = $this->_vali(['order_no.require' => '订单编号不能为空!']);
$order = $this->app->db->name('ShopOrder')->where(['mid' => $this->mid])->where($map)->find(); $order = $this->app->db->name('ShopOrder')->where(['mid' => $this->mid])->where($map)->find();
if (empty($order)) $this->error('订单查询失败!'); if (empty($order)) $this->error('订单查询失败!');
$order['list'] = $this->app->db->name('ShopOrderList')->where($map)->select()->toArray(); $order['list'] = $this->app->db->name('ShopOrderItem')->where($map)->select()->toArray();
$rlist = $this->app->db->name('ShopOrderRefund')->where($map)->whereIn('refund_status', [1, 2, 3])->select()->toArray(); $rlist = $this->app->db->name('ShopOrderRefund')->where($map)->whereIn('refund_status', [1, 2, 3])->select()->toArray();
if (count($order['list']) > 0) foreach ($order['list'] as &$vo) if (count($rlist) > 0) foreach ($rlist as $rule) { if (count($order['list']) > 0) foreach ($order['list'] as &$vo) if (count($rlist) > 0) foreach ($rlist as $rule) {
if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) { if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) {