| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace addons\Store\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_store_order_pickup}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id
- * @property int $order_id
- * @property int $mall_order_id
- * @property int $stage 期数
- * @property string $code 自提码
- * @property int|null $updated_at
- * @property int|null $created_at
- */
- class StoreOrderPickup extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_order_pickup}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'order_id', 'mall_order_id', 'stage', 'code'], 'required'],
- [['mall_id', 'store_id', 'order_id', 'mall_order_id', 'stage', 'updated_at', 'created_at'], 'integer'],
- [['code'], 'string', 'max' => 10],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => 'Store ID',
- 'order_id' => 'Order ID',
- 'mall_order_id' => 'Mall Order Id',
- 'stage' => 'Stage',
- 'code' => 'Code',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * 获取门店当前期数自提订单数量
- *
- * @param integer $store_id
- * @return int
- */
- public static function getStoreCount(int $store_id, string $stage)
- {
- return static::find()
- ->where(['store_id' => $store_id, 'stage' => $stage])
- ->count();
- }
- /**
- * 获取自提数据
- *
- * @param integer $order_id
- * @return array
- */
- public static function getPickupDataByOrderId(int $order_id)
- {
- return static::find()
- ->select('stage, code')
- ->where(['order_id' => $order_id])
- ->asArray()
- ->one();
- }
- /**
- * 通过主商城订单ID获取自提数据
- *
- * @param integer $mall_order_id
- * @return array
- */
- public static function getPickupDataByMallOrderId(int $mall_order_id)
- {
- return static::find()
- ->select('stage, code')
- ->where(['mall_order_id' => $mall_order_id])
- ->asArray()
- ->one();
- }
- /**
- * 添加自提订单
- *
- * @param integer $mall_id
- * @param integer $store_id
- * @param integer $order_id
- * @param string $stage
- * @param string $code
- * @return static|false
- */
- public static function addPickup(
- int $mall_id,
- int $store_id,
- int $order_id,
- int $mall_order_id,
- string $stage,
- string $code
- )
- {
- $model = new static;
- if (
- $model->load(compact('mall_id', 'store_id', 'order_id', 'mall_order_id', 'stage', 'code'), '') && $model->save()
- ) {
- return $model;
- }
- return false;
- }
- }
|