LocalDeliveryCourier.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\helpers\Json;
  10. use yii\db\ActiveRecord;
  11. use yii\behaviors\TimestampBehavior;
  12. /**
  13. * This is the model class for table "{{%local_delivery_courier}}".
  14. *
  15. * @property integer $saas_user_id
  16. * @property integer $type
  17. * @property integer $store_id
  18. * @property integer $state
  19. * @property integer $status
  20. * @property integer $is_auto
  21. * @property string $real_name
  22. * @property string $real_code
  23. * @property string $real_just_pic
  24. * @property string $real_back_pic
  25. * @property string $work_time
  26. * @property string $area
  27. * @property string $money
  28. * @property string $total_money
  29. * @property integer $created_at
  30. * @property integer $updated_at
  31. * @property integer $is_delete
  32. * @property integer $source
  33. * @property integer $apply_time
  34. * @property integer $max_num
  35. * @property string $mobile
  36. * @property string $avatar
  37. * @property string $address
  38. * @property float $pass_rate
  39. * @property float $star
  40. */
  41. class LocalDeliveryCourier extends \yii\db\ActiveRecord
  42. {
  43. const IS_DELETE_YES = 1;//已删除
  44. const IS_DELETE_NO = 0;//未删除
  45. const IS_STATE_AWAITING = 1;//待审核
  46. const IS_STATE_YES = 2;//审核通过
  47. const IS_STATE_NO = 3;//审核拒绝
  48. const IS_STATUS_YES = 1;//在线
  49. const IS_STATUS_NO = 0;//离线
  50. const IS_AUTO_YES = 1;//自动抢单
  51. const IS_AUTO_NO = 0;//手动抢单
  52. const SOURCE_ADD = 1;//平台添加
  53. const SOURCE_APPLY = 2;//用户申请
  54. /**
  55. * @inheritdoc
  56. */
  57. public static function tableName()
  58. {
  59. return '{{%local_delivery_courier}}';
  60. }
  61. public function behaviors()
  62. {
  63. return [
  64. [
  65. 'class' => TimestampBehavior::class,
  66. 'attributes' => [
  67. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
  68. ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
  69. ]
  70. ]
  71. ];
  72. }
  73. /**
  74. * @inheritdoc
  75. */
  76. public function rules()
  77. {
  78. return [
  79. [['saas_user_id', 'type', 'store_id', 'state', 'status', 'is_auto', 'is_delete', 'source', 'apply_time', 'max_num'], 'integer'],
  80. [['real_name', 'real_code', 'real_just_pic', 'real_back_pic','mobile', 'avatar'], 'string', 'max' => 255],
  81. [['work_time', 'area', 'address'], 'string'],
  82. [['money', 'total_money', 'pass_rate', 'star'], 'number'],
  83. ];
  84. }
  85. /**
  86. * @inheritdoc
  87. */
  88. public function attributeLabels()
  89. {
  90. return [
  91. 'id' => 'ID',
  92. 'saas_user_id' => 'saas_user表的id',
  93. 'type' => '配送员类型:1=平台配送员;2=店铺配送员;',
  94. 'store_id' => '店铺ID',
  95. 'state' => '审核状态:1待审核,2审核通过,3审核拒绝',
  96. 'status' => '在线状态:0=离线;1=在线;',
  97. 'is_auto' => '是否自动接单:0=否;1=是;',
  98. 'real_name' => '姓名',
  99. 'real_code' => '身份证号',
  100. 'real_just_pic' => '身份证照片正面',
  101. 'real_back_pic' => '身份证照片反面',
  102. 'work_time' => '工作时间段json',
  103. 'area' => '常驻区域json',
  104. 'money' => '可提现金额',
  105. 'total_money' => '总收入',
  106. 'created_at' => '创建时间',
  107. 'updated_at' => '最后一次修改时间',
  108. 'is_delete' => '是否删除:0=否;1=是;',
  109. 'source' => '用户来源:1=平台添加;2=用户申请;',
  110. 'apply_time' => '审核时间',
  111. 'max_num' => '同时最大接单数量,0=无限制',
  112. 'mobile' => '配送员电话',
  113. 'avatar' => '头像',
  114. 'address' => '详细地址',
  115. 'pass_rate' => '准时率',
  116. 'star' => '评分'
  117. ];
  118. }
  119. // 配送员可提现减少金额
  120. public static function subMoney($courier, $price, $desc = '账户提现')
  121. {
  122. $t = \Yii::$app->db->beginTransaction();
  123. try {
  124. $log = LocalDeliveryLog::saveLog($courier->saas_user_id, $price, 2, 2, 0, "配送员提现");
  125. if (!$log) {
  126. throw new \Exception('配送员金额日志记录失败');
  127. }
  128. $t->commit();
  129. } catch (\Exception $e) {
  130. $t->rollBack();
  131. return false;
  132. }
  133. return true;
  134. }
  135. // 配送员可提现增加金额
  136. public static function addMoney($store, $price, $desc = '用户下单', $order_id = 0, $user_id = 0)
  137. {
  138. $t = \Yii::$app->db->beginTransaction();
  139. try {
  140. $before = $store->price;
  141. $store->price += $price;
  142. $store->total_price += $price;
  143. if (!$store->save()) {
  144. throw new \Exception('配送员金额增加失败');
  145. }
  146. $log = new StoreAccountLog();
  147. $log->store_id = $store->id;
  148. $log->order_id = $order_id;
  149. $log->user_id = $user_id;
  150. $log->price = $price;
  151. $log->desc = $desc;
  152. $log->before = $before;
  153. $log->after = $store->price;
  154. $log->type = 1;
  155. $log->time = time();
  156. if (!$log->save()) {
  157. throw new \Exception('配送员金额日志记录失败');
  158. }
  159. $t->commit();
  160. } catch (\Exception $e) {
  161. $t->rollBack();
  162. return false;
  163. }
  164. return true;
  165. }
  166. }