SortingList.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * InventiryList.php
  4. * todo 文件描述
  5. * Created on 2024/3/26 10:13
  6. * @author: hankaige
  7. */
  8. namespace app\models;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%inventory_list}}".
  13. * @property integer $id
  14. * @property integer $store_id
  15. * @property integer $inventory_id
  16. * @property string $sorting_no
  17. * @property string $md_id
  18. * @property integer $goods_count
  19. * @property integer $order_count
  20. * @property integer $driver_id
  21. * @property integer $is_delete
  22. * @property integer $created_at
  23. */
  24. class SortingList extends \yii\db\ActiveRecord
  25. {
  26. public static function tableName()
  27. {
  28. return "{{%sorting_list}}";
  29. }
  30. public function behaviors()
  31. {
  32. return [
  33. [
  34. 'class' => TimestampBehavior::class,
  35. 'attributes' => [
  36. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  37. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  38. ]
  39. ]
  40. ];
  41. }
  42. public function rules()
  43. {
  44. return [
  45. [
  46. [
  47. 'store_id',
  48. 'inventory_id',
  49. 'sorting_no',
  50. 'goods_count',
  51. 'order_count',
  52. 'md_id'
  53. ],
  54. 'required'
  55. ],
  56. [
  57. [
  58. 'inventory_id',
  59. 'goods_count',
  60. 'order_count',
  61. 'md_id',
  62. 'driver_id'
  63. ],
  64. 'integer'
  65. ],
  66. [
  67. ['sorting_no'],
  68. 'string'
  69. ],
  70. [
  71. 'sorting_no',
  72. 'unique'
  73. ]
  74. ];
  75. }
  76. public function attributeLabels()
  77. {
  78. return [
  79. 'inventory_id' => '商城ID',
  80. 'sorting_no' => '备货单单号',
  81. 'goods_count' => '包含商品数量',
  82. 'order_count' => '包含订单数量',
  83. 'md_id' => '门店ID',
  84. 'driver_id' => '司机ID'
  85. ];
  86. }
  87. /**
  88. * 生成备货单单号
  89. * @return string
  90. * @author: hankaige
  91. * @Time: 2024/3/26 10:32
  92. */
  93. public static function createOrderNo()
  94. {
  95. while (TRUE) {
  96. $order_no = 'SL' . date('YmdHis') . mt_rand(100000, 999999);
  97. $exist_order_no = self::find()->where(['sorting_no' => $order_no])->exists();
  98. if (!$exist_order_no) {
  99. break;
  100. }
  101. }
  102. return $order_no;
  103. }
  104. public function getMd()
  105. {
  106. return $this->hasOne(Md::class, ['id' => 'md_id'])->select('id,name,province,city,district');
  107. }
  108. public function getDriver()
  109. {
  110. return $this->hasOne(MdGroupDriver::className(), ['id' => 'driver_id'])->select('id,name,mobile,code');
  111. }
  112. public function getOrder(){
  113. return $this->hasMany(SortingOrder::className(),['sorting_id'=>'id'])->with('order');
  114. }
  115. }