StoreOrderPickup.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace addons\Store\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_store_order_pickup}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id
  9. * @property int $store_id
  10. * @property int $order_id
  11. * @property int $mall_order_id
  12. * @property int $stage 期数
  13. * @property string $code 自提码
  14. * @property int|null $updated_at
  15. * @property int|null $created_at
  16. */
  17. class StoreOrderPickup extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_store_order_pickup}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'store_id', 'order_id', 'mall_order_id', 'stage', 'code'], 'required'],
  33. [['mall_id', 'store_id', 'order_id', 'mall_order_id', 'stage', 'updated_at', 'created_at'], 'integer'],
  34. [['code'], 'string', 'max' => 10],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => 'Mall ID',
  45. 'store_id' => 'Store ID',
  46. 'order_id' => 'Order ID',
  47. 'mall_order_id' => 'Mall Order Id',
  48. 'stage' => 'Stage',
  49. 'code' => 'Code',
  50. 'updated_at' => 'Updated At',
  51. 'created_at' => 'Created At',
  52. ];
  53. }
  54. /**
  55. * 获取门店当前期数自提订单数量
  56. *
  57. * @param integer $store_id
  58. * @return int
  59. */
  60. public static function getStoreCount(int $store_id, string $stage)
  61. {
  62. return static::find()
  63. ->where(['store_id' => $store_id, 'stage' => $stage])
  64. ->count();
  65. }
  66. /**
  67. * 获取自提数据
  68. *
  69. * @param integer $order_id
  70. * @return array
  71. */
  72. public static function getPickupDataByOrderId(int $order_id)
  73. {
  74. return static::find()
  75. ->select('stage, code')
  76. ->where(['order_id' => $order_id])
  77. ->asArray()
  78. ->one();
  79. }
  80. /**
  81. * 通过主商城订单ID获取自提数据
  82. *
  83. * @param integer $mall_order_id
  84. * @return array
  85. */
  86. public static function getPickupDataByMallOrderId(int $mall_order_id)
  87. {
  88. return static::find()
  89. ->select('stage, code')
  90. ->where(['mall_order_id' => $mall_order_id])
  91. ->asArray()
  92. ->one();
  93. }
  94. /**
  95. * 添加自提订单
  96. *
  97. * @param integer $mall_id
  98. * @param integer $store_id
  99. * @param integer $order_id
  100. * @param string $stage
  101. * @param string $code
  102. * @return static|false
  103. */
  104. public static function addPickup(
  105. int $mall_id,
  106. int $store_id,
  107. int $order_id,
  108. int $mall_order_id,
  109. string $stage,
  110. string $code
  111. )
  112. {
  113. $model = new static;
  114. if (
  115. $model->load(compact('mall_id', 'store_id', 'order_id', 'mall_order_id', 'stage', 'code'), '') && $model->save()
  116. ) {
  117. return $model;
  118. }
  119. return false;
  120. }
  121. }