| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace app\modules\admin\models\integralAppreciation;
- use app\models\Goods;
- use app\models\IntegralAppreciationGoods;
- use app\models\IntegralAppreciationPoolSub;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\User;
- use yii\base\Model;
- class OrderForm extends Model
- {
- public $store_id;
- public $order_no;
- public $user_name;
- public $goods_name;
- public $start_time;
- public $end_time;
- public function rules()
- {
- return [
- [['store_id'], 'integer'],
- [['order_no', 'user_name', 'goods_name', 'start_time', 'end_time'], 'string']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'store_id' => '商城ID',
- 'order_no' => '订单编号',
- 'user_name' => '用户名称',
- 'goods_name' => '商品名称',
- 'start_time' => '',
- 'end_time' => '',
- ];
- }
- /**
- * 列表
- */
- public function getList() {
- $store_id = $this->store_id;
- $order_no = $this->order_no;
- $goods_name = $this->goods_name;
- $start_time = $this->start_time;
- $end_time = $this->end_time;
- $user_name = $this->user_name;
- $query = IntegralAppreciationPoolSub::find()->alias('ps')
- ->leftJoin(['o' => Order::tableName()], 'ps.order_id = o.id')
- ->leftJoin(['od' => OrderDetail::tableName()], 'o.id = od.order_id')
- ->leftJoin(['u' => User::tableName()], 'o.user_id = u.id')
- ->where(['ps.reflux_type' => IntegralAppreciationPoolSub::REFLUX_TYPE_ORDER, 'ps.store_id' => $store_id])->andWhere(['>', 'ps.order_id', 0]);
- if ($order_no) {
- $query->andWhere(['like', 'o.order_no', $order_no]);
- }
- if ($goods_name) {
- $query->andWhere(['like', 'od.goods_name', $goods_name]);
- }
- if ($user_name) {
- $query->andWhere(['like', 'u.nickname', $user_name]);
- }
- if ($goods_name) {
- $query->andWhere(['like', 'od.goods_name', $goods_name]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'ps.created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'ps.created_at', $end_time]);
- }
- $query->orderBy('ps.id DESC')
- ->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');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['trade_status'] = intval($item['trade_status']);
- $item['trade_status_text'] = Order::TRADE_STATUS_TEXT[$item['trade_status']];
- $item['goods_list'] = OrderDetail::find()->where(['order_id' => $item['id']])
- ->select('goods_name, pic, num, attr, total_price')->asArray()->all();
- foreach ($item['goods_list'] as &$goods_item) {
- $goods_item['attr'] = json_decode($goods_item['attr'], true);
- }
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $list
- ];
- }
- }
|