| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace addons\Agent\common\models;
- use common\enums\StatusEnum;
- use common\models\order\OrderDetail;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_agent_goods_repurchase".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $item_id 商品id
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class AgentGoodsRepurchase extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_agent_goods_repurchase';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'item_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'item_id' => 'Item ID',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 判断当前用户是否购买过当前商品
- * @param int $mall_id
- * @param int $user_id
- * @param int $order_id
- * @param int $goods_id
- * @return bool
- */
- public static function isBuyCurrentGoods(int $mall_id, int $user_id, int $order_id, int $goods_id)
- {
- return OrderDetail::find()->where(['mall_id' => $mall_id])
- ->andWhere(['user_id' => $user_id])
- ->andWhere(['<>', 'order_id', $order_id])
- ->andWhere(['goods_id' => $goods_id])
- ->andWhere(['order_status' => [
- 1, 2, 3, 4, -1, -2, -5
- ]])
- ->andWhere(['status' => StatusEnum::ENABLED])
- ->count() > 0;
- }
- /**
- * @param int $mall_id
- * @param int $goods_id
- * @return bool
- */
- public static function isAloneSetting(int $mall_id, int $goods_id)
- {
- return self::find()->where(['mall_id' => $mall_id])
- ->andWhere(['item_id' => $goods_id])
- ->andWhere(['status' => StatusEnum::ENABLED])->count() > 0;
- }
- }
|