StoreExchangeOrder.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/18
  6. */
  7. namespace app\models\store;
  8. use crmeb\basic\BaseModel;
  9. use crmeb\traits\ModelTrait;
  10. /**
  11. * TODO 秒杀产品Model
  12. * Class StoreSeckill
  13. * @package app\models\store
  14. */
  15. class StoreExchangeOrder extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'store_exchange_order';
  27. use ModelTrait;
  28. public static function orderList($where)
  29. {
  30. $model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*');
  31. if ($where['order'] != '') {
  32. $model = $model->order(self::setOrder($where['order']));
  33. } else {
  34. $model = $model->order('a.id desc');
  35. }
  36. return ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  37. }
  38. public static function getOrderWhere($where, $model, $aler = '', $join = '')
  39. {
  40. if (isset($where['status']) && $where['status'] != '') $model = self::statusWhere($where['status'], $model, $aler);
  41. if (isset($where['store_id']) && $where['store_id'] != '' && $where['store_id'] != -1) $model = $model->where($aler . 'store_id', $where['store_id']);
  42. if (isset($where['user_phone']) && $where['user_phone'] != '')
  43. $model = $model->where($aler . 'user_phone', 'LIKE', "%$where[user_phone]%");
  44. if (isset($where['real_name']) && $where['real_name'] != '')
  45. $model = $model->where($aler . 'order_id|' . $aler . 'real_name|' . $aler . 'user_phone' . ($join ? '|' . $join . '.nickname|' . $join . '.uid' : ''), 'LIKE', "%$where[real_name]%");
  46. if (isset($where['data']) && $where['data'] !== '')
  47. $model = self::getModelTime($where, $model, $aler . 'add_time');
  48. return $model;
  49. }
  50. public static function getAdminOrderDetail($orderId, $field = '*', $other_where = [])
  51. {
  52. return self::where('order_id', $orderId)->where($other_where)->field($field)->find();
  53. }
  54. public static function statusWhere($status, $model = null, $alert = '')
  55. {
  56. if ($model == null) $model = new self;
  57. if ('' === $status)
  58. return $model;
  59. else if ($status == 0)//待使用
  60. return $model->where($alert . 'status', 0)->where($alert . 'refund_status', 0);
  61. else if ($status == 1)//已使用
  62. return $model->where($alert . 'status', 1)->where($alert . 'refund_status', 0);
  63. else if ($status == -1)//退款中
  64. return $model->where($alert . 'refund_status', 1);
  65. else if ($status == -2)//已退款
  66. return $model->where($alert . 'refund_status', 2);
  67. else if ($status == -3)//退款
  68. return $model->where($alert . 'refund_status', 'in', '1,2');
  69. else
  70. return $model;
  71. }
  72. public static function getUserOrderSearchList($uid, $type, $page, $limit, $search)
  73. {
  74. if ($search) {
  75. $order = self::searchUserOrder($uid, $search) ?: [];
  76. $list = $order == false ? [] : [$order];
  77. } else {
  78. $list = self::getUserOrderList($uid, $type, $page, $limit);
  79. }
  80. foreach ($list as $k => $order) {
  81. $list[$k]['order'] = StoreOrder::get($order['oid']);
  82. $list[$k]['cart_info'] = StoreOrderCartInfo::where('oid', $order['oid'])
  83. ->where('cart_id', $order['cart_id'])
  84. ->value('cart_info');
  85. if (is_string($list[$k]['cart_info'])) $list[$k]['cart_info'] = json_decode($list[$k]['cart_info'], true);
  86. }
  87. return $list;
  88. }
  89. public static function searchUserOrder($uid, $order_id)
  90. {
  91. $order = self::where('uid|gift_uid', $uid)->where('order_id', $order_id)->where('is_del', 0)
  92. ->order('add_time DESC')->select();
  93. if (!$order)
  94. return false;
  95. else
  96. return $order;
  97. }
  98. public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8)
  99. {
  100. if ($page) $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid|gift_uid', $uid)
  101. ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
  102. else $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid|gift_uid', $uid)
  103. ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
  104. return $list;
  105. }
  106. public static function statusByWhere($status, $uid = 0, $model = null)
  107. {
  108. if ($model == null) $model = new self;
  109. if ('' === $status)
  110. return $model;
  111. else if ($status == 0)//待使用
  112. return $model->where('status', 0)->where('refund_status', 0);
  113. else if ($status == 1)//已使用
  114. return $model->where('status', 1)->where('refund_status', 0);
  115. else if ($status == -1)//退款中
  116. return $model->where('refund_status', 1);
  117. else if ($status == -2)//已退款
  118. return $model->where('refund_status', 2);
  119. else if ($status == -3)//退款
  120. return $model->where('refund_status', 'IN', '1,2');
  121. else
  122. return $model;
  123. }
  124. }