| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\modules\admin\models;
- use app\models\Goods;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderForm;
- use yii\base\Model;
- class IntegralOrderForm extends Model
- {
- public $store_id;
- public $order_id;
- public $status;
- public $order_no;
- public $goods_name;
- public $mobile;
- public $start_time;
- public $end_time;
- public $name;
- public function rules()
- {
- return [
- [['store_id', 'status', 'order_id'], 'integer'],
- [['order_no', 'goods_name', 'mobile', 'start_time', 'end_time', 'name'], 'string']
- ];
- }
- public function orderList() {
- $store_id = $this->store_id;//商城id
- $status = $this->status;//订单状态
- $order_no = $this->order_no;//订单编号
- $goods_name = $this->goods_name;//商品名称
- $mobile = $this->mobile;//手机号
- $start_time = $this->start_time;//开始时间
- $end_time = $this->end_time;//结束时间
- $name = $this->name;//收货人
- $order_id = $this->order_id;
- $query = Order::find()->alias('o')->where(['o.order_type' => Order::ORDER_TYPE_INTEGRAL, 'is_delete' => 0, 'store_id' => $store_id]);
- if ($status !== null && intval($status) !== -1 && in_array($status, [0, 2, 3, 1])) {
- $query->andWhere(['o.trade_status' => $status]);
- }
- if ($order_no) {
- $query->andWhere(['o.order_no' => $order_no]);
- }
- if ($order_id) {
- $query->andWhere(['o.id' => $order_id]);
- }
- if ($goods_name) {
- $query->leftJoin(['od' => OrderDetail::tableName()], 'o.id = od.oder_id');
- $query->andWhere(['LIKE', 'od.goods_name', $goods_name]);
- }
- if ($mobile) {
- $query->andWhere(['LIKE', 'o.mobile', $mobile]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'o.created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'o.created_at', $end_time]);
- }
- if ($name) {
- $query->andWhere(['LIKE', 'o.name', $name]);
- }
- $query->orderBy('o.created_at desc')->select('o.id, o.order_no, o.integral_price, o.total_price, o.pay_price, o.name, o.created_at, o.express_price, o.trade_status, o.address, o.mobile, o.is_pay, o.express, o.express_no, o.confirm_time, o.send_time, o.pay_time, o.apply_delete, o.pay_type, o.remark');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['confirm_time'] = $item['confirm_time'] ? date('Y-m-d H:i:s', $item['confirm_time']) : '';
- $item['send_time'] = $item['send_time'] ? date('Y-m-d H:i:s', $item['send_time']) : '';
- $item['pay_time'] = $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '';
- $item['trade_status'] = (int)$item['trade_status'];
- $item['is_pay'] = (int)$item['is_pay'];
- $item['apply_delete'] = (int)$item['apply_delete'];
- $item['pay_type'] = (int)$item['pay_type'];
- $item['goods_list'] = OrderDetail::find()->alias('od')->where(['od.order_id' => $item['id']])
- ->leftJoin(['g' => Goods::tableName()], 'od.goods_id = g.id')
- ->select(['od.num', 'od.total_price', 'g.goods_no', 'od.attr', 'od.food_ext_goods', 'od.is_level', 'od.batch_price_tips', 'name' => 'od.goods_name','od.pic', 'od.goods_info', 'od.delivery_type', 'od.shop_id', 'od.goods_id', 'g.attr attrs', 'od.integral_price', 'g.unit'])->asArray()->all();
- foreach ($item['goods_list'] as &$goods) {
- $goods['form'] = OrderForm::findAll(['goods_id' => $goods['goods_id'], 'order_id' => $item['id']]);
- $goods['attr_list'] = json_decode($goods['attr'], true);
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- 'express_list' => (new OrderListForm())->getExpressList(),
- ]
- ];
- }
- }
|