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; } }