OrderLogic.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\mobile\logic;
  3. use app\model\CommonModel;
  4. use app\model\OrderModel;
  5. use think\response\Json;
  6. class OrderLogic extends BaseLogic
  7. {
  8. //订单列表
  9. public static function list(array $data = []): Json
  10. {
  11. $db = OrderModel::alias('a')
  12. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  13. ->where(['a.is_del'=>CommonModel::$del_normal, 'a.uid' => self::$aid]);
  14. if ($data['status'] != '') $db->where('a.status', $data['status']);
  15. $count = $db->count('a.id');
  16. $list = $db
  17. ->field('a.id,a.orderCode,b.good_name,a.num,a.status,a.addtime,a.type,a.price,a.total_price')
  18. ->page($data['page'], $data['size'])
  19. ->order('a.id', 'desc')
  20. ->select()
  21. ->toArray();
  22. return json_show(CommonModel::$success, '获取订单列表成功', ['count' => $count, 'list' => $list]);
  23. }
  24. //订单详情
  25. public static function info(int $id = 0): Json
  26. {
  27. $rs = OrderModel::alias('a')
  28. ->field('a.id,a.orderCode,a.status,a.addtime,a.type,b.good_name,a.num,c.contactor,c.mobile,c.addr,c.addr_code,a.price,a.total_price,a.post_name,a.post_code,a.remark,"支付流水号" p')
  29. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  30. ->leftJoin('addr c', 'c.id=a.addr_id AND c.is_del=' . CommonModel::$del_normal)
  31. ->leftJoin('pay_info d', 'd.id=a.pay_info_id')
  32. ->where(['a.is_del' => CommonModel::$del_normal, 'a.id' => $id, 'a.uid' => self::$aid])
  33. ->withAttr('addr', function ($val, $da) {
  34. return $da['addr_code'] ? get_addr_name($da['addr_code']) . $val : $val;
  35. })
  36. ->findOrEmpty()
  37. ->toArray();
  38. return $rs ? json_show(CommonModel::$success, '获取订单详情成功', $rs) : json_show(CommonModel::$error_param, '该订单不存在');
  39. }
  40. }