TimestampBehavior::class, ] ]; } /** * @inheritdoc */ public function rules() { return [ [['id', 'store_id', 'cat_id', 'user_id', 'saas_user_id', 'level', 'is_delete', 'open_status', 'status', 'province_id', 'city_id', 'district_id'], 'integer'], [['created_at', 'updated_at', 'lat', 'lng'], 'safe'], [['name', 'desc', 'tel', 'logo', 'reason', 'area', 'form'], 'string'], [['name'], 'required'], ['name', 'string', 'min' => 2, 'max' => 12], ['tel', 'string', 'min' => 11, 'max' => 11], ['open_status', 'integer', 'min' => 0, 'max' => 1], ['book_start_time', 'compare', 'compareAttribute' => 'book_end_time', 'operator' => '<='], ['book_end_time', 'compare', 'compareValue' => '2359', 'operator' => '<='], ]; } public function beforeSave($insert) { if (parent::beforeSave($insert)) { if($this->user_id > 0){ if($this->isNewRecord){ $is = self::find()->where(['user_id' => $this->user_id, 'status' => self::STATUS_VALID])->one(); }else{ $is = self::find()->where(['user_id' => $this->user_id, 'status' => self::STATUS_VALID])->andWhere(['!=', 'id', $this->id])->one(); } if($is){ $this->addError('user_id', '操作失败,此用户[****'. mb_substr($is->name, -1) . $is->id .']已存在!'); return false; } } return true; } return false; } public static function afterOrderSave($insert, $changedAttributes, $order) { try{ if($order->order_type != Order::ORDER_TYPE_WORKER){ return; } WorkerOrderExt::afterOrderSave($insert, $changedAttributes, $order); } catch (\Exception $ex) { //debug_log(['afterOrderSave', $insert, $changedAttributes, $ex], __CLASS__ . '.log'); } } public function getLevelInfo() { return $this->hasOne(WorkerLevel::class, ['level' => 'level'])->andWhere(['store_id' => $this->store_id]); } public function getPics() { return $this->hasMany(WorkerPic::class, ['worker_id' => 'id'])->andWhere(['is_delete' => 0]); } public function getGoods() { return $this->hasMany(WorkerGoods::class, ['worker_id' => 'id'])->andWhere(['status' => 1]); } public function showBookTime() { $this->book_start_time = self::formatTime($this->book_start_time); $this->book_end_time = self::formatTime($this->book_end_time); } public static function formatTime($time){ $time = str_pad($time, 4, 0, STR_PAD_LEFT); return substr($time, -4, 2) . ':' . substr($time, -2); } public static function getStatusName($status){ $arr = [ self::STATUS_WAIT_AUDIT => '未审核', self::STATUS_VALID => '已审核', self::STATUS_REJECT => '已拒绝', self::STATUS_CLOSE => '已禁用', ]; return $arr[$status] ?? ''; } }