| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\utils\Notice\NoticeSend;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%booking_order_ext}}".
- *
- * @property integer $id
- */
- class BookingOrderExt extends \yii\db\ActiveRecord
- {
-
- const IGNORE_ORDER_IDS = 'IGNORE_ORDER_IDS';
-
- const STATUS_EXT_WAIT_PAY = 5; //待支付
- const STATUS_EXT_WAIT_SYS_CONFIRM = 10; //待系统确认
- const STATUS_EXT_HAS_SYS_CONFIRM = 20; //系统确认/待开始
- const STATUS_EXT_START = 50; //进行中
- const STATUS_EXT_CANCEL = 70; //取消
- const STATUS_EXT_FINISH = 100; //完成
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%booking_order_ext}}';
- }
- public function behaviors()
- {
- return [];
- }
- public static function afterOrderSave($insert, $changedAttributes, $order) {
- try{
- if($order->order_type != 2){
- return;
- }
- self::statusAfterOrderSave($insert, $changedAttributes, $order);
- } catch (\Exception $ex) {
- //debug_log([__METHOD__, $insert, $changedAttributes, $ex->getMessage()], __CLASS__ . '.log');
- }
- }
- public static function statusAfterOrderSave($insert, $changedAttributes, $order) {
- //debug_log([__METHOD__, $insert, isset($changedAttributes['is_pay']), $order->is_pay, $changedAttributes, $order], __CLASS__ . '.log');
- if($insert){
- $self = new self();
- $self->order_id = $order->id;
- $self->store_id = $order->store_id;
- $save = $self->save();
- if(!$save){
- //debug_log([__METHOD__, $self->getErrors()], __CLASS__ . '.log');
- }
- }
- if(isset($changedAttributes['is_pay']) && ($order->is_pay == 1)){
- //debug_log([__METHOD__, 'is_pay', $order->is_pay, $order->pay_price, $order->id], __CLASS__ . '.log');
- // if($order->pay_price == 0){
- // self::updateAll(['status_ext' => self::STATUS_EXT_HAS_SYS_CONFIRM], ['order_id' => $order->id, 'status_ext' => self::STATUS_EXT_WAIT_PAY]);
- // }else{
- self::updateAll(['status_ext' => self::STATUS_EXT_WAIT_SYS_CONFIRM], ['order_id' => $order->id, 'status_ext' => self::STATUS_EXT_WAIT_PAY]);
- // }
- }
- if(isset($changedAttributes['trade_status']) && ($order->trade_status == Order::ORDER_FLOW_CANCEL)){
- self::updateAll(['status_ext' => self::STATUS_EXT_CANCEL], ['order_id' => $order->id]);
- }
- if(isset($changedAttributes['trade_status']) && ($order->trade_status == Order::ORDER_FLOW_CONFIRM)){
- self::updateAll(['status_ext' => self::STATUS_EXT_FINISH], ['order_id' => $order->id]);
- }
- if(isset($changedAttributes['clerk_id']) && ($order->clerk_id > 0)){
- $user = User::findOne($order->clerk_id);
- $saasUser = SaasUser::findOne(['mobile' => $user['binding']]);
- if($user && $saasUser){
- $md_staff = MdStaff::findOne(['saas_user_id' => $saasUser['id'], 'store_id' => $order->store_id]);
- if($md_staff){
- self::updateAll(['worker_id' => $md_staff['id'], 'worker_name' => $md_staff['name'], 'time_has_bind' => time()], ['order_id' => $order->id]);
- }
- }
- }
- // //debug_log(['statusAfterOrderSave', $insert, $changedAttributes, $addr], __CLASS__ . '.log');
- }
- public static function afterOrderDetailSave($insert, $changedAttributes, $orderDetail) {
- try{
- $attr = json_decode($orderDetail['attr'], true);
- self::updateAll(['booking_time_start' => $attr['start_date'], 'booking_time_end' => $attr['end_date']], ['order_id' => $orderDetail->order_id]);
- } catch (\Exception $ex) {
- //debug_log([__METHOD__, $insert, $changedAttributes, $ex->getMessage()], __CLASS__ . '.log');
- }
- }
- public function setWorker($worker_id, $worker_name) {
- $this->worker_id = $worker_id;
- $this->worker_name = $worker_name;
- $this->time_has_bind = time();
- NoticeSend::bookExamine($this->order_id, 1);
- return $this;
- }
- public static function getWorkerOrderGroupStatus($worker_id) {
- $order_count = self::find()->where(['worker_id' => $worker_id])
- ->andWhere(['!=', 'status_ext', self::STATUS_EXT_CANCEL])
- ->select('count(1) cc, status_ext')
- ->groupBy('status_ext')->asArray()->all();
- return $order_count;
- }
- }
|