OrderForm.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\modules\admin\models\integralAppreciation;
  3. use app\models\Goods;
  4. use app\models\IntegralAppreciationGoods;
  5. use app\models\IntegralAppreciationPoolSub;
  6. use app\models\Order;
  7. use app\models\OrderDetail;
  8. use app\models\User;
  9. use yii\base\Model;
  10. class OrderForm extends Model
  11. {
  12. public $store_id;
  13. public $order_no;
  14. public $user_name;
  15. public $goods_name;
  16. public $start_time;
  17. public $end_time;
  18. public function rules()
  19. {
  20. return [
  21. [['store_id'], 'integer'],
  22. [['order_no', 'user_name', 'goods_name', 'start_time', 'end_time'], 'string']
  23. ];
  24. }
  25. public function attributeLabels()
  26. {
  27. return [
  28. 'store_id' => '商城ID',
  29. 'order_no' => '订单编号',
  30. 'user_name' => '用户名称',
  31. 'goods_name' => '商品名称',
  32. 'start_time' => '',
  33. 'end_time' => '',
  34. ];
  35. }
  36. /**
  37. * 列表
  38. */
  39. public function getList() {
  40. $store_id = $this->store_id;
  41. $order_no = $this->order_no;
  42. $goods_name = $this->goods_name;
  43. $start_time = $this->start_time;
  44. $end_time = $this->end_time;
  45. $user_name = $this->user_name;
  46. $query = IntegralAppreciationPoolSub::find()->alias('ps')
  47. ->leftJoin(['o' => Order::tableName()], 'ps.order_id = o.id')
  48. ->leftJoin(['od' => OrderDetail::tableName()], 'o.id = od.order_id')
  49. ->leftJoin(['u' => User::tableName()], 'o.user_id = u.id')
  50. ->where(['ps.reflux_type' => IntegralAppreciationPoolSub::REFLUX_TYPE_ORDER, 'ps.store_id' => $store_id])->andWhere(['>', 'ps.order_id', 0]);
  51. if ($order_no) {
  52. $query->andWhere(['like', 'o.order_no', $order_no]);
  53. }
  54. if ($goods_name) {
  55. $query->andWhere(['like', 'od.goods_name', $goods_name]);
  56. }
  57. if ($user_name) {
  58. $query->andWhere(['like', 'u.nickname', $user_name]);
  59. }
  60. if ($goods_name) {
  61. $query->andWhere(['like', 'od.goods_name', $goods_name]);
  62. }
  63. if ($start_time) {
  64. $start_time = strtotime($start_time);
  65. $query->andWhere(['>=', 'ps.created_at', $start_time]);
  66. }
  67. if ($end_time) {
  68. $end_time = strtotime($end_time);
  69. $query->andWhere(['<=', 'ps.created_at', $end_time]);
  70. }
  71. $query->orderBy('ps.id DESC')
  72. ->select('o.id, o.order_no, o.total_price, o.pay_price, o.trade_status, ps.amount, ps.created_at, u.avatar_url avatar, u.nickname');
  73. $list = pagination_make($query);
  74. foreach ($list['list'] as &$item) {
  75. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  76. $item['trade_status'] = intval($item['trade_status']);
  77. $item['trade_status_text'] = Order::TRADE_STATUS_TEXT[$item['trade_status']];
  78. $item['goods_list'] = OrderDetail::find()->where(['order_id' => $item['id']])
  79. ->select('goods_name, pic, num, attr, total_price')->asArray()->all();
  80. foreach ($item['goods_list'] as &$goods_item) {
  81. $goods_item['attr'] = json_decode($goods_item['attr'], true);
  82. }
  83. }
  84. return [
  85. 'code' => 0,
  86. 'msg' => '',
  87. 'data' => $list
  88. ];
  89. }
  90. }