| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /**
- * InventiryList.php
- * todo 文件描述
- * Created on 2024/3/26 10:13
- * @author: hankaige
- */
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%inventory_list}}".
- * @property integer $id
- * @property integer $store_id
- * @property integer $inventory_id
- * @property string $sorting_no
- * @property string $md_id
- * @property integer $goods_count
- * @property integer $order_count
- * @property integer $driver_id
- * @property integer $is_delete
- * @property integer $created_at
- */
- class SortingList extends \yii\db\ActiveRecord
- {
- public static function tableName()
- {
- return "{{%sorting_list}}";
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- public function rules()
- {
- return [
- [
- [
- 'store_id',
- 'inventory_id',
- 'sorting_no',
- 'goods_count',
- 'order_count',
- 'md_id'
- ],
- 'required'
- ],
- [
- [
- 'inventory_id',
- 'goods_count',
- 'order_count',
- 'md_id',
- 'driver_id'
- ],
- 'integer'
- ],
- [
- ['sorting_no'],
- 'string'
- ],
- [
- 'sorting_no',
- 'unique'
- ]
- ];
- }
- public function attributeLabels()
- {
- return [
- 'inventory_id' => '商城ID',
- 'sorting_no' => '备货单单号',
- 'goods_count' => '包含商品数量',
- 'order_count' => '包含订单数量',
- 'md_id' => '门店ID',
- 'driver_id' => '司机ID'
- ];
- }
- /**
- * 生成备货单单号
- * @return string
- * @author: hankaige
- * @Time: 2024/3/26 10:32
- */
- public static function createOrderNo()
- {
- while (TRUE) {
- $order_no = 'SL' . date('YmdHis') . mt_rand(100000, 999999);
- $exist_order_no = self::find()->where(['sorting_no' => $order_no])->exists();
- if (!$exist_order_no) {
- break;
- }
- }
- return $order_no;
- }
- public function getMd()
- {
- return $this->hasOne(Md::class, ['id' => 'md_id'])->select('id,name,province,city,district');
- }
- public function getDriver()
- {
- return $this->hasOne(MdGroupDriver::className(), ['id' => 'driver_id'])->select('id,name,mobile,code');
- }
- public function getOrder(){
- return $this->hasMany(SortingOrder::className(),['sorting_id'=>'id'])->with('order');
- }
- }
|