GoodsOrderServer.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\GoodsOrder;
  4. class GoodsOrderServer
  5. {
  6. /**
  7. * Notes:获取订单列表
  8. * @param string $keywords
  9. * @param int $page
  10. * @param int $limit
  11. * @return array
  12. * User: ZQ
  13. * Date: 2022/10/13
  14. */
  15. public static function getOrderList(int $page, int $limit, string $keywords,$order_type_model)
  16. {
  17. [$list, $count] = GoodsOrder::getOrderList($page, $limit,$keywords,$order_type_model);
  18. return compact('list', 'page', 'limit', 'count');
  19. }
  20. /**
  21. * Notes:获取订单详情
  22. * @param int $order_id
  23. * @return int
  24. * User: ZQ
  25. * Date: 2022/10/13
  26. */
  27. public static function orderInfo($order_id)
  28. {
  29. $where = [];
  30. $where['order_id'] = $order_id;
  31. $result = GoodsOrder::with(['user','detail'])->where($where)
  32. ->leftJoin('merchant_shop','shop_id','=','life_market_order.order_shop_id')
  33. ->first(['life_market_order.*','merchant_shop.shop_name']);
  34. if (!empty($result)){
  35. return $result;
  36. }else{
  37. return false;
  38. }
  39. }
  40. /**
  41. * Notes:发货
  42. * User: YCP
  43. * Date: 2022/11/9
  44. */
  45. public static function orderDelivery($params,$admin_id)
  46. {
  47. GoodsOrder::affairBegin();
  48. try {
  49. $where = [];
  50. $where['order_id'] = $params['order_id'];
  51. $data['order_express_no'] = $params['order_express_no'];//快递单号
  52. $data['order_express_company'] = $params['order_express_company'];//物流公司
  53. $data['order_status'] = $params['order_status']; // 1待发货2已发货,待收货3已收货待评价4已完成5退款中6已退款7待使用8已使用9待预约10退款驳回
  54. if($data['order_status'] == 2){
  55. $data['order_deliver_time'] = time();
  56. }
  57. if($data['order_status'] == 10){
  58. $data['order_reject_reason'] = $params['order_reject_reason'];
  59. }
  60. $result = GoodsOrder::where($where)->update($data);
  61. if (!empty($result)){
  62. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '订单发货-编号: ' . $params['order_id'];
  63. plog('life-order-delivery', '超市订单发货', $msg);
  64. GoodsOrder::affairCommit();
  65. return true;
  66. }else{
  67. return false;
  68. }
  69. }catch (\Exception $exception){
  70. GoodsOrder::affairRollback();
  71. throw new \Exception($exception->getMessage(), 500);
  72. }
  73. }
  74. /**
  75. * Notes:修改订单支付状态
  76. * @param string $order_id
  77. * @param int $order_finish
  78. * @return int
  79. * User: YCP
  80. * Date: 2022/11/28
  81. */
  82. public static function updatePayStatus($order_id, $order_pay_status)
  83. {
  84. GoodsOrder::affairBegin();
  85. try {
  86. $where = [];
  87. $where['order_id'] = $order_id;
  88. $data = [];
  89. $data['order_pay_status'] = $order_pay_status;
  90. if($order_pay_status == 1){
  91. $data['order_pay_time'] = time();
  92. }else{
  93. $data['order_pay_time'] = "";
  94. }
  95. $result = GoodsOrder::where($where)->update($data);
  96. if ($result !== false){
  97. $user_id = GoodsOrder::where($where)->value('order_user_id');
  98. events('createUserNews', ['log_type' => 0, 'log_uid' => $user_id, 'log_content' => '您的订单支付成功了!']);
  99. GoodsOrder::affairCommit();
  100. return true;
  101. }
  102. throw new \Exception('操作失败!');
  103. }catch (\Exception $exception){
  104. GoodsOrder::affairRollback();
  105. throw new \Exception($exception->getMessage(), 500);
  106. }
  107. }
  108. }