| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\constants\OptionSetting;
- use app\models\AgentGoodsInstallLog;
- use app\models\common\ExpressDetail;
- use app\models\DeliveryRules;
- use app\models\FoodFlag;
- use app\models\Goods;
- use app\models\GoodsBook;
- use app\models\Mch;
- use app\models\SaaSLeaguePriceLog;
- use app\models\Store;
- use app\models\UserStringCodeOrder;
- use app\modules\admin\models\ActivityCutPriceForm;
- use app\models\Md;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderRefund;
- use app\models\User;
- use app\models\UserCoupon;
- use app\models\AccountLog;
- use app\modules\client\models\v1\order\OrderForm;
- use app\utils\Delivery\Delivery;
- use yii\base\BaseObject;
- use yii\data\Pagination;
- use app\utils\Notice\NoticeAction;
- use yii\helpers\Json;
- use app\models\DeliveryInfo;
- class OrderListForm extends OrderForm
- {
- public $store_id;
- public $user_id;
- public $status;
- public $delivery_status;
- public $delivery_type;
- public $page;
- public $limit = 20;
- public $order_id;
- public $order_no;
- public $key;
- public $nowlatitude;
- public $nowlongitude;
- public function rules()
- {
- return [
- [['page', 'limit', 'status', 'delivery_type'], 'integer'],
- [['page'], 'default', 'value' => 1],
- [['limit'], 'default', 'value' => 20],
- [['order_no'], 'default', 'value' => 0],
- [['order_id', 'key'],'trim'],
- [['nowlongitude', 'nowlatitude'], 'safe'],
- ];
- }
- public function search()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $query = Order::find()->where([
- 'is_delete' => 0,
- 'saas_id' =>get_saas_user_id(),
- 'user_delete' => 0
- ]);
- if($this->store_id !=226){
- $query->andWhere([
- 'or',
- ['store_id' => $this->store_id],
- ['origin_store_id' => $this->store_id]
- ]);
- }else{
- $query->andWhere([
- 'store_id' => $this->store_id,
- ]);
- }
- $query->andWhere([
- '<>', 'order_type', Order::ORDER_TYPE_WORKER
- ]);
- if (isset($this->status) && $this->status > -1) {
- $query->andWhere([
- '<>', 'trade_status', Order::ORDER_FLOW_CANCEL
- ]);
- }
- // if (get_md_id() > 0) {
- // $query->andWhere(['OR', ['md_id' => get_md_id()], ['order_type' => [1, 2]]]);
- // }
- if ($this->status == 0) {//待付款
- $query->andWhere([
- 'is_pay' => Order::IS_PAY_FALSE,
- ])->andWhere(['!=', 'pay_type' , 2])->andWhere(['!=', 'trade_status', 1]);
- if($this->order_id){
- // 是不是查询指定的带支付订单
- $query->andWhere(['id'=>$this->order_id]);
- }
- }
- if ($this->status == 1) {//待发货
- $query->andWhere([
- 'or',
- ['trade_status' => Order::ORDER_FLOW_NO_SEND],
- ['pay_type' => 2, 'trade_status' => Order::ORDER_FLOW_DEFAULT]
- ])->andWhere(['or', ['is_pay' => 1], ['pay_type' => 2]]);
- }
- if ($this->status == 2) {//待收货
- $query->andWhere([
- 'trade_status' => Order::ORDER_FLOW_SEND,
- ]);
- }
- if ($this->status == 3) {//已完成
- $query->andWhere([
- 'trade_status' => Order::ORDER_FLOW_CONFIRM,
- ]);
- }
- if ($this->status == 4) {//售后订单
- return $this->getRefundList();
- }
- $query->andWhere(['is_recycle' => 0]);
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- /* @var Order[] $list */
- $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->all();
- $new_list = [];
- $pay_type_list = OrderForm::getPayType([],['huodao']);
- foreach ($list as $order) {
- // 预约订单超过15分钟未支付自动取消
- if (time() - $order->created_at > 15 * 60 && $order->trade_status != Order::ORDER_FLOW_CANCEL && $order->is_pay == 0 && !in_array($order->pay_type, [2, Order::PAY_TYPE_OFFLINE]) && ActivityCutPriceForm::orderCanCancel($order)) {
- $t = \Yii::$app->db->beginTransaction();
- $order->trade_status = Order::ORDER_FLOW_CANCEL;
- $order->updated_at = time();
- $orderInfo = $order->save();
- if($order->user_coupon_id > 0){
- UserCoupon::updateAll(['is_use' => 0], ['id' => $order->user_coupon_id]);
- }
- //如果是积分商品退回积分
- // if($order->integral_price > 0){
- // $log = AccountLog::saveLog($order->user_id, $order->integral_price, AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_REFUND_ORDER, $order->id, "商城订单退积分,订单号:{$order->order_no}");
- // }else{
- // $log = true;
- // }
- if ($order->take_price > 0){
- $league_order = SaaSLeaguePriceLog::findOne(['order_id' => $order->id,'type'=>36]);
- $league_order_d = SaaSLeaguePriceLog::findOne(['order_id' => $order->id,'type'=>4]);
- if (!$league_order && $league_order_d){
- $title = '订单取消返还:'.$order->order_no;
- SaaSLeaguePriceLog::addLog($order->saas_id,$order->store_id,$order->take_price, UserStringCodeOrder::TYPE_LEAGUE_PRICE[UserStringCodeOrder::TYPE_ORDER_FLOW_CANCEL],$order->id,0,0,$title);
- }
- }
- $log = true;
- // 退还积分
- $integral = Json::decode($order->integral);
- // 减去当前用户账户积分
- $log2 = true;
- // if ($integral['forehead_integral'] > 0) {
- // $log2 = AccountLog::saveLog($order->user_id, $integral['forehead_integral'], AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_REFUND_ORDER, $order->id, "商城订单退积分,订单号:{$order->order_no}");
- // } elseif ($order->integral_price > 0) {
- // $log = AccountLog::saveLog($order->user_id, $order->integral_price, AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_INCOME, AccountLog::TYPE_PLATFORM_REFUND_ORDER, $order->id, "商城订单退积分,订单号:{$order->order_no}");
- // }
- if (!$orderInfo || !$log || !$log2) { //
- $t->rollBack();
- } else {
- $t->commit();
- }
- }
- $order_detail_list = OrderDetail::findAll(['order_id' => $order->id, 'is_delete' => 0]);
- $goods_list = [];
- $is_can_confirm = true;
- // 获取联动2+1商品条件
- $holderLevelConditionDay = null;
- $holderLevelOption = \app\utils\Share\BonusPool::getShareHolderLevelOption($this->store_id);
- foreach ($order_detail_list as $order_detail) {
- $goods = Json::encode($order_detail->goods_info);
- if (!$goods) {
- continue;
- }
- foreach ($holderLevelOption as $holderLevelOptionItem) {
- if (\in_array($order_detail->goods_id, $holderLevelOptionItem['goods_ids'])) {
- $holderLevelConditionDay = $holderLevelOptionItem['day'];
- break;
- }
- }
- $goods_model = Goods::findOne($order_detail->goods_id);
- $delivery_rules = DeliveryRules::find()->where(['id' => $goods_model->delivery_rules_id, 'is_delete' => 0, 'status' => 1, 'store_id' => get_store_id()])->select('type, times, days, name')->asArray()->one();
- if ($delivery_rules) {
- $days = "下单" . $delivery_rules['days'] . "天后";
- $delivery_rules['times'] =
- (int)$delivery_rules['type'] === 1 ? $days : date("m月d日 H:i:s", $delivery_rules['times']);
- $delivery_rules['type'] .= '';
- }
- //判断是否可点击确认收货
- $is_can_confirm_sub = ((bool)AgentGoodsInstallLog::findOne(['order_detail_id' => $order_detail->id, 'status' => [0, 1], 'is_need_install' => 1, 'order_type' => AgentGoodsInstallLog::ORDER_TYPE_NORMAL]));
- if ($is_can_confirm_sub) {
- $is_can_confirm = false;
- }
- $goods_pic = isset($order_detail->pic) ? $order_detail->pic : $goods['cover_pic'];
- $goods_list[] = (object)[
- 'goods_id' => isset($goods['id']) ? $goods['id'] : $order_detail->goods_id,
- 'goods_pic' => $goods_pic,
- 'goods_name' => $order_detail->goods_name,
- 'num' => $order_detail->num,
- 'price' => $order_detail->total_price,
- 'attr_list' => json_decode($order_detail->attr),
- 'food_ext_goods' => (array)json_decode($order_detail['food_ext_goods'], true),
- 'integral_price' => $order_detail->integral_price,
- 'delivery_rules' => $delivery_rules ?: null,
- 'shop_coin_attr'=>$order_detail->shop_coin_attr,
- ];
- }
- $qrcode = null;
- $mch = [
- 'id' => 0,
- 'name' => '平台自营',
- 'logo' => '',
- ];
- if ($order->md_id) {
- $md = Md::findOne($order->md_id);
- }
- if ($order->mch_id) {
- $mch = Mch::findOne($order->mch_id);
- }
- if($order->order_type == 7){
- $mch['name'] = '积分兑换';
- }
- //新增店铺名称逻辑
- $store_info = \Yii::$app->db->createCommand("SELECT * FROM cyy_store WHERE id = :id")
- ->bindValue(':id', $order->store_id)
- ->queryOne();
-
- if(($order->origin_store_id >0) && ($order->origin_store_id != $order->store_id)){
- $mch['name'] =$store_info['name'];
- }
- $orderRefund = OrderRefund::find()->where(['store_id' => $order->store_id, 'order_id' => $order->id])->exists();
- $deliveryInfo = null;
- if ($order->is_delivery == 1) {
- $deliveryInfo = DeliveryInfo::find()->where(['order_no' => $order->order_no])->one();
- }
- $is_order_refund = $order_refund_enable = 0;
- if ($orderRefund) {
- $is_order_refund = 1;
- } else {
- $is_order_refund = 0;
- }
- if ($order->is_pay == 1 && ($order->trade_status == Order::ORDER_FLOW_SEND || $order->trade_status == Order::ORDER_FLOW_CONFIRM)) {
- $order_refund_enable = 1;
- if (intval($order->is_sale)) {
- $order_refund_enable = 0;
- }
- } else {
- $order_refund_enable = 0;
- }
- if ($order->pay_type == 2 && intval($order->is_pay) === 0) {
- $is_can_confirm = false;
- }
- if ($order->trade_status == Order::ORDER_FLOW_CONFIRM && intval($order->is_sale) === 0) {
- // if ($holderLevelConditionDay === null) {
- // $after_sale_time = Option::get(OptionSetting::STORE_AFTER_SALE_TIME, $this->store_id);
- // } else {
- // $after_sale_time = $holderLevelConditionDay;
- // }
- // if ((time() - $order->confirm_time) > $after_sale_time['value'] * 86400) {//超过可售后时间
- $order_refund_enable = 1;
- // }
- }
- // 查询物流信息
- $model = new ExpressDetail();
- $model->express = $order->express;
- $model->express_no = $order->express_no;
- $model->receive_mobile = $order->mobile;
- $model->store_id = $this->store_id;
- $res = $model->search();
- $express_detail = [];
- if ($res['code'] != 0) {
- $express_detail['list'] = [];
- $express_detail['status'] = 0;
- $express_detail['status_text'] = '未知';
- } else {
- $express_detail = $res['data'];
- }
- $food_pay_type = [];
- $store = Store::findOne($order->store_id);
- if (!empty($store)) {
- if ($order->food_flag_id > 0) {
- if ($order->md_id > 0) {
- $md = Md::findOne($order->md_id);
- $food_payment = $md->food_payment;
- } else {
- $store = Store::findOne($order->store_id);
- $food_payment = $store->food_payment;
- }
- $food_pay_list = [];
- if (!empty($food_payment)) {
- $food_pay_type = Json::decode($food_payment);
- foreach ($food_pay_type as &$value) {
- if ($value['key'] == 'friend') {
- $value['payment'] = 7;
- if(!$value['name']){
- $value['name'] = "朋友代付";
- }
- }
- if ($value['key'] == 'alipay') {
- $value['payment'] = 4;
- if(!$value['name']){
- $value['name'] = "支付宝支付";
- }
- }
- if ($value['key'] == 'wechat') {
- $value['payment'] = 1;
- if(!$value['name']){
- $value['name'] = "微信支付";
- }
- }
- if ($value['key'] == 'huodao') {
- $value['payment'] = 2;
- if(!$value['name']){
- $value['name'] = "货到付款";
- }
- }
- }
- $food_pay_list = $food_pay_type;
- }
- foreach ($food_pay_list as $k => $val) {
- if ($val['payment'] == 4 && is_wechat_platform() || ($val['payment'] == 4 && intval($val['value']) === 0)) {
- unset($food_pay_list[$k]);
- }
- if ($val['payment'] == 1 && is_alipay_platform() || ($val['payment'] == 1 && intval($val['value']) === 0)) {
- unset($food_pay_list[$k]);
- }
- if ($val['payment'] == 7 && intval($val['value']) === 0) {
- unset($food_pay_list[$k]);
- }
- if ($val['payment'] == 2 && intval($val['value']) === 0) {
- unset($food_pay_list[$k]);
- }
- if ($val['payment'] == 5 && intval($val['value']) === 0) {
- unset($food_pay_list[$k]);
- }
- }
- $food_pay_list = array_values($food_pay_list);
- // 点餐支付方式
- $food_pay_type = $food_pay_list;
- }
- }
- $is_get_coin =1;
- if(($order->trade_status == 3) && $order->is_get_coin == 0){
- //查询商品是不是
- foreach ($goods_list as $k1 => $v1) {
- $cloud_goods_id = \Yii::$app->db->createCommand("SELECT cloud_goods_id FROM cyy_cloud_goods_bind WHERE goods_id = :goods_id")
- ->bindValue(':goods_id', $v1->goods_id) // 改为箭头运算符
- ->queryScalar();
- $count_crry = \Yii::$app->db->createCommand("SELECT cloud_goods_id FROM cyy_goods_wallet WHERE cloud_goods_id = :cloud_goods_id")
- ->bindValue(':cloud_goods_id', $cloud_goods_id)
- ->queryScalar();
- if ($count_crry) {
- if(($order->created_at)>1741968000){
- $is_get_coin = 0;
- }
- }
- $shop_coin_attr = json_decode($v1->shop_coin_attr);
- if($shop_coin_attr){
- $is_get_coin = 0;
- }
- }
-
- }
- $new_list[] = (object)[
- 'store_id_first'=>$order->store_id,
- 'store_id'=>$order->origin_store_id,
- 'is_get_coin'=>$is_get_coin,
- 'is_sale' => intval($order->is_sale),
- 'is_order_refund' => $is_order_refund,
- 'order_refund_enable' => $order_refund_enable,
- 'order_id' => $order->id,
- 'order_no' => $order->order_no,
- 'add_time' => $order->created_at,
- 'goods_list' => $goods_list,
- 'total_price' => $order->total_price,
- 'pay_price' => sprintf("%1.2f", $order->pay_price),
- 'is_pay' => $order->is_pay,
- 'is_comment' => $order->is_comment,
- 'is_offline' => $order->is_offline,
- 'qrcode' => $qrcode,
- 'offline_qrcode' => $order->offline_qrcode,
- 'express' => $order->express,
- 'mch' => $mch,
- 'type' => $order->type,
- 'pay_type' => $order->pay_type,
- 'refund' => $orderRefund,
- 'apply_delete' => $order->apply_delete,
- 'trade_status' => $order->trade_status,
- 'delivery_fee' => $deliveryInfo ? $deliveryInfo->fee : 0,
- 'is_delivery' => $order->is_delivery,
- 'order_type' => $order->order_type,
- 'md_name' => $mch->name ?? ($md->name ?? "平台自营"),
- 'express_detail' => $express_detail,
- 'express_no' => $order->express_no,
- 'is_can_confirm' => $is_can_confirm,
- 'pay_type_list' => $food_pay_type ?: $pay_type_list
- ];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $new_list,
- 'pay_type_list' => $pay_type_list,
- 'revoke_tpl'=>'',
- 'template_id' => NoticeAction::getSendTamplateId(['order_cancel'], is_h5() ? 'wxaapi' : 'miapp'),
- 'cancel_reason' => Delivery::$validReason
- ],
- ];
- }
- private function getRefundList()
- {
- $query = OrderRefund::find()->alias('or')
- ->leftJoin(['od' => OrderDetail::tableName()], 'od.id=or.order_detail_id')
- ->leftJoin(['o' => Order::tableName()], 'o.id=or.order_id')
- ->where([
- 'or.store_id' => $this->store_id,
- 'or.user_id' => $this->user_id,
- 'or.is_delete' => 0,
- 'o.is_delete' => 0,
- 'od.is_delete' => 0,
- ]);
- if($this->order_id){
- $query->andWhere(['o.id' => $this->order_id]);
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- $list = $query->select('o.id AS order_id,o.order_no,or.id AS order_refund_id,od.goods_id,or.created_at,od.num,od.total_price,od.attr,or.refund_price,or.type,or.status,or.is_agree,or.is_user_send,od.goods_info, od.goods_name, od.pic')
- ->limit($pagination->limit)->offset($pagination->offset)->orderBy('or.id DESC')->asArray()->all();
- $new_list = [];
- foreach ($list as $item) {
- $goods = Json::decode($item['goods_info']) ?:Goods::find()->where(['id' => $item['goods_id']])->asArray()->one();
- if (!$goods) {
- continue;
- }
- $new_list[] = (object)[
- 'order_id' => intval($item['order_id']),
- 'order_no' => $item['order_no'],
- 'goods_list' => [(object)[
- 'goods_id' => intval($goods->id),
- 'goods_pic' => $item['pic'] ?: $goods['cover_pic'],
- 'goods_name' => $item['goods_name'],
- 'num' => intval($item['num']),
- 'price' => doubleval(sprintf('%.2f', $item['total_price'])),
- 'attr_list' => json_decode($item['attr']),
- ]],
- 'addtime' => date('Y-m-d H:i', $item['created_at']),
- 'refund_price' => doubleval(sprintf('%.2f', $item['refund_price'])),
- 'refund_type' => $item['type'],
- 'refund_status' => $item['status'],
- 'order_refund_id' => $item['order_refund_id'],
- 'is_agree' => $item['is_agree'],
- 'is_user_send' => $item['is_user_send'],
- ];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $new_list,
- ],
- ];
- }
- public function getNewRefundList()
- {
- $after_sale_time = Option::get(OptionSetting::STORE_AFTER_SALE_TIME, $this->store_id);
- $new_list = [];
- if (!$this->status) {
- $query = Order::find()->alias('o')
- ->where([
- 'o.store_id' => $this->store_id,
- 'o.user_id' => $this->user_id,
- 'o.is_delete' => 0,
- ]);
- // if (get_md_id()) {
- // $query->andWhere(['o.md_id' => get_md_id()]);
- // }
- $query->andWhere(['o.trade_status' => Order::ORDER_FLOW_CONFIRM]);
- $query->andWhere(['>', 'o.confirm_time', time() - $after_sale_time['value'] * 86400]);
- $list = $query->select('o.pay_price, o.confirm_time, o.id AS order_id,o.order_no,o.created_at')->orderBy('o.id DESC')->asArray()->all();
- foreach ($list as $item) {
- $detail_goods = OrderDetail::find()->where(['order_id' => $item['order_id'], 'is_refund' => 0])->asArray()->all();
- if (empty($detail_goods)) {
- continue;
- }
- $detail_goods = OrderDetail::find()->where(['order_id' => $item['order_id']])->asArray()->all();
- $order_data = [
- 'order_id' => intval($item['order_id']),
- 'order_no' => $item['order_no'],
- 'pay_price' => $item['pay_price'],
- 'goods_list' => [],
- 'addtime' => date('Y-m-d H:i', $item['created_at']),
- 'refund_price' => isset($item['refund_price']) ? doubleval(sprintf('%.2f', $item['refund_price'])) : 0,
- 'refund_type' => isset($item['type']) ? $item['type'] : 0,
- 'refund_status' => isset($item['status']) ? $item['status'] : 0,
- 'order_refund_id' => isset($item['order_refund_id']) ? $item['order_refund_id'] : 0,
- 'is_agree' => isset($item['is_agree']) ? $item['is_agree'] : 0,
- 'is_user_send' => isset($item['is_user_send']) ? $item['is_user_send'] : 0,
- ];
- $goods_list = [];
- foreach ($detail_goods as $detail) {
- $goods_list[] = [
- 'goods_id' => intval($detail['goods_id']),
- 'goods_pic' => $detail['pic'],
- 'goods_name' => $detail['goods_name'],
- 'num' => intval($detail['num']),
- 'price' => doubleval(sprintf('%.2f', $detail['total_price'])),
- 'attr_list' => json_decode($detail['attr']),
- ];
- }
- $order_data['goods_list'] = $goods_list;
- $new_list[] = $order_data;
- }
- }
- // 处理中 或者 已完成
- if ($this->status == 1 || $this->status == 2) {
- $query = OrderRefund::find()->alias('or')
- ->leftJoin(['o' => Order::tableName()], 'o.id=or.order_id')
- ->where([
- 'or.store_id' => $this->store_id,
- 'or.user_id' => $this->user_id,
- 'or.is_delete' => 0,
- 'o.is_delete' => 0,
- 'or.user_delete' => 0
- ]);
- // if (get_md_id()) {
- // $query->andWhere(['or.md_id' => get_md_id()]);
- // }
- if ($this->status == 1) {
- $query->andWhere(['or.status' => OrderRefund::STATUS_IN, 'or.is_user_cancel' => 0]);
- }
- if ($this->status == 2) {
- $query->andWhere(['or', ['or.is_user_cancel' => 1], ['in', 'or.status', OrderRefund::$is_handle_status]]);
- }
- $list = $query->select('or.is_user_cancel, or.order_detail_id,o.pay_price, o.confirm_time, o.id AS order_id,o.order_no,or.id AS order_refund_id,or.created_at,or.refund_price,or.type,or.status,or.is_agree,or.is_user_send')->orderBy('or.id DESC')->asArray()->all();
- if (!empty($list)) {
- foreach ($list as $item) {
- $order_data = [
- 'is_user_cancel' => intval($item['is_user_cancel']),
- 'order_id' => intval($item['order_id']),
- 'order_no' => $item['order_no'],
- 'pay_price' => $item['pay_price'],
- 'goods_list' => [],
- 'addtime' => date('Y-m-d H:i', $item['created_at']),
- 'refund_price' => isset($item['refund_price']) ? doubleval(sprintf('%.2f', $item['refund_price'])) : 0,
- 'refund_type' => isset($item['type']) ? $item['type'] : 0,
- 'refund_status' => isset($item['status']) ? $item['status'] : 0,
- 'order_refund_id' => isset($item['order_refund_id']) ? $item['order_refund_id'] : 0,
- 'is_agree' => isset($item['is_agree']) ? $item['is_agree'] : 0,
- 'is_user_send' => isset($item['is_user_send']) ? $item['is_user_send'] : 0,
- ];
- $detail_id = Json::decode($item['order_detail_id']);
- $detail_goods = OrderDetail::find()->where(['order_id' => $item['order_id'], 'is_refund' => 1])->andWhere(['in', 'id', $detail_id])->asArray()->all();
- $goods_list = [];
- $price = 0;
- foreach ($detail_goods as $detail) {
- $goods_list[] = [
- 'goods_id' => intval($detail['goods_id']),
- 'goods_pic' => $detail['pic'],
- 'goods_name' => $detail['goods_name'],
- 'num' => intval($detail['num']),
- 'price' => doubleval(sprintf('%.2f', $detail['total_price'])),
- 'attr_list' => json_decode($detail['attr']),
- 'is_refund' => $detail['is_refund']
- ];
- $price += $detail['total_price'];
- }
- $order_data['pay_price'] = $price;
- $order_data['goods_list'] = $goods_list;
- $new_list[] = $order_data;
- }
- }
- }
- $data = array_slice($new_list, ($this->page - 1) * $this->limit, $this->limit);
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => count($new_list),
- 'page_count' => ceil(count($new_list) / $this->limit),
- 'list' => $data,
- ],
- ];
- }
- public static function getCountData($store_id, $user_id)
- {
- $form = new OrderListForm();
- $form->limit = 1;
- $form->store_id = $store_id;
- $form->user_id = $user_id;
- $data = [];
- $form->status = -1;
- $res = $form->searchOrderCount();
- $data['all'] = $res;
- $form->status = 0;
- $res = $form->searchOrderCount();
- $data['status_0'] = $res;
- $form->status = 1;
- $res = $form->searchOrderCount();
- $data['status_1'] = $res;
- $form->status = 2;
- $res = $form->searchOrderCount();
- $data['status_2'] = $res;
- $form->status = 3;
- $res = $form->searchOrderCount();
- $data['status_3'] = $res;
- return $data;
- }
- /**
- * 获取订单数方法
- * @return array|int|string
- */
- public function searchOrderCount()
- {
- $query = Order::find()->where([
- 'is_delete' => 0,
- 'user_delete' => 0,
- 'store_id' => $this->store_id,
- 'user_id' => $this->user_id,
- ]);
- $query->andWhere(['!=', 'order_type', 6]);
- // if (get_md_id()) {
- // $query->andWhere(['md_id' => get_md_id()]);
- // }
- if (isset($this->status) && $this->status > -1) {
- $query->andWhere([
- '<>', 'trade_status', Order::ORDER_FLOW_CANCEL
- ]);
- }
- if ($this->status == 0) {//待付款
- $query->andWhere([
- 'is_pay' => Order::IS_PAY_FALSE,
- ])->andWhere(['!=', 'pay_type' , 2]);
- }
- if ($this->status == 1) {//待发货
- $query->andWhere([
- 'trade_status' => Order::ORDER_FLOW_NO_SEND,
- ])->andWhere(['or', ['is_pay' => 1], ['pay_type' => 2]]);
- }
- if ($this->status == 2) {//待收货
- $query->andWhere([
- 'trade_status' => Order::ORDER_FLOW_SEND,
- ]);
- }
- if ($this->status == 3) {//已完成
- $query->andWhere([
- 'trade_status' => Order::ORDER_FLOW_CONFIRM,
- 'is_comment'=> 0,
- ]);
- }
- $query->andWhere(['is_recycle' => 0]);
- return $query->count();
- }
- //获取积分兑换商品列表
- public function getIntegralList(){
- $query = Order::find()->alias('o')->leftJoin(["d"=>OrderDetail::tablename()],'o.id = d.order_id');
- $query->where([
- 'o.is_delete' => 0,
- 'o.user_delete' => 0,
- 'o.store_id' => $this->store_id,
- 'o.user_id' => $this->user_id,
- 'o.order_type' => 7,
- 'o.is_pay' => 1
- ]);
- $query->select("o.id,o.pay_price,o.order_no,o.integral_price,o.trade_status,d.goods_name,d.goods_id,d.num,d.total_price,d.integral_price,d.pic,d.goods_info");
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$val){
- $val['goods_info'] = json_decode($val['goods_info'],true);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- ],
- ];
- }
- public function getHashList(){
- $store_id = $this->store_id;
- $query = Order::find()->where([
- 'is_delete' => 0,
- 'user_delete' => 0,
- 'saas_id' => get_saas_user_id(),
- 'is_pay' => 1
- ]);
- $query->select(['id','order_no','tx_has',
- 'FROM_UNIXTIME(confirm_time) as confirm_time'])->andWhere('tx_has IS NOT NULL')->orderBy('confirm_time DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list
- ];
- }
- }
|