| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%worker}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $cat_id
- * @property integer $user_id
- * @property integer $saas_user_id
- * @property integer $level
- * @property string $name
- * @property string $desc
- * @property string $tel
- * @property string $logo
- * @property integer $is_delete
- * @property integer $book_start_time
- * @property integer $book_end_time
- * @property integer $open_status
- * @property integer $status
- * @property string $reason
- * @property string $area
- * @property integer $created_at
- * @property integer $updated_at
- * @property string $lat
- * @property string $lng
- * @property string $form
- * @property integer $province_id
- * @property integer $city_id
- * @property integer $district_id
- */
- class Worker extends \yii\db\ActiveRecord
- {
- const STATUS_WAIT_AUDIT = 0; //未审核
- const STATUS_VALID = 1; //已审核
- const STATUS_REJECT = 2; //已拒绝
- const STATUS_CLOSE = 3; //禁用
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%worker}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => 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] ?? '';
- }
- }
|