| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\helpers\Json;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%local_delivery_courier}}".
- *
- * @property integer $saas_user_id
- * @property integer $type
- * @property integer $store_id
- * @property integer $state
- * @property integer $status
- * @property integer $is_auto
- * @property string $real_name
- * @property string $real_code
- * @property string $real_just_pic
- * @property string $real_back_pic
- * @property string $work_time
- * @property string $area
- * @property string $money
- * @property string $total_money
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $is_delete
- * @property integer $source
- * @property integer $apply_time
- * @property integer $max_num
- * @property string $mobile
- * @property string $avatar
- * @property string $address
- * @property float $pass_rate
- * @property float $star
- */
- class LocalDeliveryCourier extends \yii\db\ActiveRecord
- {
- const IS_DELETE_YES = 1;//已删除
- const IS_DELETE_NO = 0;//未删除
-
- const IS_STATE_AWAITING = 1;//待审核
- const IS_STATE_YES = 2;//审核通过
- const IS_STATE_NO = 3;//审核拒绝
- const IS_STATUS_YES = 1;//在线
- const IS_STATUS_NO = 0;//离线
- const IS_AUTO_YES = 1;//自动抢单
- const IS_AUTO_NO = 0;//手动抢单
-
- const SOURCE_ADD = 1;//平台添加
- const SOURCE_APPLY = 2;//用户申请
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%local_delivery_courier}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => 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;
- }
- }
|