TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at' ] ] ]; } /** * @inheritdoc */ public function rules() { return [ [['saas_user_id', 'type', 'store_id', 'state', 'status', 'is_auto', 'is_delete', 'source', 'apply_time', 'max_num'], 'integer'], [['real_name', 'real_code', 'real_just_pic', 'real_back_pic','mobile', 'avatar'], 'string', 'max' => 255], [['work_time', 'area', 'address'], 'string'], [['money', 'total_money', 'pass_rate', 'star'], 'number'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'saas_user_id' => 'saas_user表的id', 'type' => '配送员类型:1=平台配送员;2=店铺配送员;', 'store_id' => '店铺ID', 'state' => '审核状态:1待审核,2审核通过,3审核拒绝', 'status' => '在线状态:0=离线;1=在线;', 'is_auto' => '是否自动接单:0=否;1=是;', 'real_name' => '姓名', 'real_code' => '身份证号', 'real_just_pic' => '身份证照片正面', 'real_back_pic' => '身份证照片反面', 'work_time' => '工作时间段json', 'area' => '常驻区域json', 'money' => '可提现金额', 'total_money' => '总收入', 'created_at' => '创建时间', 'updated_at' => '最后一次修改时间', 'is_delete' => '是否删除:0=否;1=是;', 'source' => '用户来源:1=平台添加;2=用户申请;', 'apply_time' => '审核时间', 'max_num' => '同时最大接单数量,0=无限制', 'mobile' => '配送员电话', 'avatar' => '头像', 'address' => '详细地址', 'pass_rate' => '准时率', 'star' => '评分' ]; } // 配送员可提现减少金额 public static function subMoney($courier, $price, $desc = '账户提现') { $t = \Yii::$app->db->beginTransaction(); try { $log = LocalDeliveryLog::saveLog($courier->saas_user_id, $price, 2, 2, 0, "配送员提现"); if (!$log) { throw new \Exception('配送员金额日志记录失败'); } $t->commit(); } catch (\Exception $e) { $t->rollBack(); return false; } return true; } // 配送员可提现增加金额 public static function addMoney($store, $price, $desc = '用户下单', $order_id = 0, $user_id = 0) { $t = \Yii::$app->db->beginTransaction(); try { $before = $store->price; $store->price += $price; $store->total_price += $price; if (!$store->save()) { throw new \Exception('配送员金额增加失败'); } $log = new StoreAccountLog(); $log->store_id = $store->id; $log->order_id = $order_id; $log->user_id = $user_id; $log->price = $price; $log->desc = $desc; $log->before = $before; $log->after = $store->price; $log->type = 1; $log->time = time(); if (!$log->save()) { throw new \Exception('配送员金额日志记录失败'); } $t->commit(); } catch (\Exception $e) { $t->rollBack(); return false; } return true; } }