StoreExchangeOrder.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 getList($where)
  39. {
  40. $model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*');
  41. if ($where['order'] != '') {
  42. $model = $model->order(self::setOrder($where['order']));
  43. } else {
  44. $model = $model->order('a.id desc');
  45. }
  46. $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  47. $count = $model->count();
  48. return compact('data', 'count');
  49. }
  50. public static function getOrderWhere($where, $model, $aler = '', $join = '')
  51. {
  52. if (isset($where['status']) && $where['status'] != '') $model = self::statusWhere($where['status'], $model, $aler);
  53. if (isset($where['store_id']) && $where['store_id'] != '' && $where['store_id'] != -1) $model = $model->where($aler . 'store_id', $where['store_id']);
  54. if (isset($where['user_phone']) && $where['user_phone'] != '')
  55. $model = $model->where($aler . 'user_phone', 'LIKE', "%$where[user_phone]%");
  56. if (isset($where['real_name']) && $where['real_name'] != '')
  57. $model = $model->where($aler . 'order_id|' . $aler . 'real_name|' . $aler . 'user_phone' . ($join ? '|' . $join . '.nickname|' . $join . '.uid' : ''), 'LIKE', "%$where[real_name]%");
  58. if (isset($where['data']) && $where['data'] !== '')
  59. $model = self::getModelTime($where, $model, $aler . 'add_time');
  60. return $model;
  61. }
  62. public static function getAdminOrderDetail($orderId, $field = '*', $other_where = [])
  63. {
  64. return self::where('order_id', $orderId)->where($other_where)->field($field)->find();
  65. }
  66. public static function statusWhere($status, $model = null, $alert = '')
  67. {
  68. if ($model == null) $model = new self;
  69. if ('' === $status)
  70. return $model;
  71. else if ($status == 0)//待使用
  72. return $model->where($alert . 'status', 0)->where($alert . 'refund_status', 0);
  73. else if ($status == 1)//已使用
  74. return $model->where($alert . 'status', 1)->where($alert . 'refund_status', 0);
  75. else if ($status == -1)//退款中
  76. return $model->where($alert . 'refund_status', 1);
  77. else if ($status == -2)//已退款
  78. return $model->where($alert . 'refund_status', 2);
  79. else if ($status == -3)//退款
  80. return $model->where($alert . 'refund_status', 'in', '1,2');
  81. else
  82. return $model;
  83. }
  84. public static function getUserOrderSearchList($uid, $type, $page, $limit, $search)
  85. {
  86. if ($search) {
  87. $order = self::searchUserOrder($uid, $search) ?: [];
  88. $list = $order == false ? [] : [$order];
  89. } else {
  90. $list = self::getUserOrderList($uid, $type, $page, $limit);
  91. }
  92. foreach ($list as $k => $order) {
  93. $list[$k]['order'] = StoreOrder::get($order['oid']);
  94. $list[$k]['cart_info'] = StoreOrderCartInfo::where('oid', $order['oid'])
  95. ->where('cart_id', $order['cart_id'])
  96. ->value('cart_info');
  97. if (is_string($list[$k]['cart_info'])) $list[$k]['cart_info'] = json_decode($list[$k]['cart_info'], true);
  98. }
  99. return $list;
  100. }
  101. public static function searchUserOrder($uid, $order_id)
  102. {
  103. $order = self::where('uid|gift_uid', $uid)->where('order_id', $order_id)->where('is_del', 0)
  104. ->order('add_time DESC')->select();
  105. if (!$order)
  106. return false;
  107. else
  108. return $order;
  109. }
  110. public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8)
  111. {
  112. if ($page) $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid|gift_uid', $uid)
  113. ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
  114. else $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid|gift_uid', $uid)
  115. ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
  116. return $list;
  117. }
  118. public static function statusByWhere($status, $uid = 0, $model = null)
  119. {
  120. if ($model == null) $model = new self;
  121. if ('' === $status)
  122. return $model;
  123. else if ($status == 0)//待使用
  124. return $model->where('status', 0)->where('refund_status', 0);
  125. else if ($status == 1)//已使用
  126. return $model->where('status', 1)->where('refund_status', 0);
  127. else if ($status == -1)//退款中
  128. return $model->where('refund_status', 1);
  129. else if ($status == -2)//已退款
  130. return $model->where('refund_status', 2);
  131. else if ($status == -3)//退款
  132. return $model->where('refund_status', 'IN', '1,2');
  133. else
  134. return $model;
  135. }
  136. }