AgentGoodsRepurchase.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace addons\Agent\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\order\OrderDetail;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_agent_goods_repurchase".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $item_id 商品id
  12. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at
  14. * @property int $updated_at
  15. */
  16. class AgentGoodsRepurchase extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return 'qimall_addons_agent_goods_repurchase';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'item_id', 'status', 'created_at', 'updated_at'], 'integer'],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => 'ID',
  41. 'mall_id' => 'Mall ID',
  42. 'item_id' => 'Item ID',
  43. 'status' => 'Status',
  44. 'created_at' => 'Created At',
  45. 'updated_at' => 'Updated At',
  46. ];
  47. }
  48. /**
  49. * 判断当前用户是否购买过当前商品
  50. * @param int $mall_id
  51. * @param int $user_id
  52. * @param int $order_id
  53. * @param int $goods_id
  54. * @return bool
  55. */
  56. public static function isBuyCurrentGoods(int $mall_id, int $user_id, int $order_id, int $goods_id)
  57. {
  58. return OrderDetail::find()->where(['mall_id' => $mall_id])
  59. ->andWhere(['user_id' => $user_id])
  60. ->andWhere(['<>', 'order_id', $order_id])
  61. ->andWhere(['goods_id' => $goods_id])
  62. ->andWhere(['order_status' => [
  63. 1, 2, 3, 4, -1, -2, -5
  64. ]])
  65. ->andWhere(['status' => StatusEnum::ENABLED])
  66. ->count() > 0;
  67. }
  68. /**
  69. * @param int $mall_id
  70. * @param int $goods_id
  71. * @return bool
  72. */
  73. public static function isAloneSetting(int $mall_id, int $goods_id)
  74. {
  75. return self::find()->where(['mall_id' => $mall_id])
  76. ->andWhere(['item_id' => $goods_id])
  77. ->andWhere(['status' => StatusEnum::ENABLED])->count() > 0;
  78. }
  79. }