FoodOrderServer.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifeFoodOrder;
  4. use app\admin\model\LifeFoodOrderDetail;
  5. class FoodOrderServer
  6. {
  7. /**
  8. * Notes:获取订单列表
  9. * @param string $keywords
  10. * @param int $page
  11. * @param int $limit
  12. * @return array
  13. * User: ZQ
  14. * Date: 2022/10/13
  15. */
  16. public static function getOrderList(int $page, int $limit, string $keywords)
  17. {
  18. [$list, $count] = LifeFoodOrder::getOrderList($page, $limit,$keywords);
  19. if (!empty($list)){
  20. foreach ($list as $k => $v){
  21. $list[$k]['order_create_time'] = date('Y-m-d H:i:s',$v['order_create_time']);
  22. if (!empty($v['order_update_time'])){
  23. $list[$k]['order_update_time'] = date('Y-m-d H:i:s',$v['order_update_time']);
  24. }
  25. if (!empty($v['detail'])){
  26. foreach ($v['detail'] as $key => $value){
  27. $list[$k]['detail'][$key]['detail_create_time'] = date('Y-m-d H:i:s',$value['detail_create_time']);
  28. if (!empty($value['detail_update_time'])){
  29. $list[$k]['detail'][$key]['detail_update_time'] = date('Y-m-d H:i:s',$value['detail_update_time']);
  30. }
  31. }
  32. }
  33. }
  34. }
  35. return compact('list', 'page', 'limit', 'count');
  36. }
  37. /**
  38. * Notes:获取订单详情
  39. * @param int $order_id
  40. * @return int
  41. * User: ZQ
  42. * Date: 2022/10/13
  43. */
  44. public static function orderInfo($order_id)
  45. {
  46. $where = [];
  47. $where['order_id'] = $order_id;
  48. $result = LifeFoodOrder::with(['user','detail'])->where($where)
  49. ->leftJoin('merchant_shop','shop_id','=','life_healthy_order.order_shop_id')
  50. ->first(['life_healthy_order.*','merchant_shop.shop_name']);
  51. if (!empty($result)){
  52. if (!empty($result)){
  53. $result['order_create_time'] = date('Y-m-d H:i:s',$result['order_create_time']);
  54. if (!empty($v['order_update_time'])){
  55. $result['order_update_time'] = date('Y-m-d H:i:s',$result['order_update_time']);
  56. }
  57. if (!empty($result['detail'])){
  58. foreach ($result['detail'] as $key => $value){
  59. $result['detail'][$key]['detail_create_time'] = date('Y-m-d H:i:s',$value['detail_create_time']);
  60. if (!empty($value['detail_update_time'])){
  61. $result['detail'][$key]['detail_update_time'] = date('Y-m-d H:i:s',$value['detail_update_time']);
  62. }
  63. }
  64. }
  65. }
  66. return $result;
  67. }else{
  68. return false;
  69. }
  70. }
  71. /**
  72. * Notes:修改订单支付状态
  73. * @param string $order_id
  74. * @param int $order_finish
  75. * @return int
  76. * User: YCP
  77. * Date: 2022/11/28
  78. */
  79. public static function updatePayStatus($order_id, $order_pay_status)
  80. {
  81. LifeFoodOrder::affairBegin();
  82. try {
  83. $where = [];
  84. $where['order_id'] = $order_id;
  85. $data = [];
  86. $data['order_pay_status'] = $order_pay_status;
  87. if($order_pay_status == 1){
  88. $data['order_pay_time'] = time();
  89. }else{
  90. $data['order_pay_time'] = "";
  91. }
  92. $result = LifeFoodOrder::where($where)->update($data);
  93. if ($result !== false){
  94. LifeFoodOrder::affairCommit();
  95. return true;
  96. }
  97. throw new \Exception('操作失败!');
  98. }catch (\Exception $exception){
  99. LifeFoodOrder::affairRollback();
  100. throw new \Exception($exception->getMessage(), 500);
  101. }
  102. }
  103. }