CommunityGoodsSetting.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\Community\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. /**
  6. * This is the model class for table "qimall_addons_community_goods_setting".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $goods_id Goods ID
  11. * @property int $enable 是否开启社区社区团购[0关闭,1开启]
  12. * @property string $supported_logistics 支持物流方式[1:快递配送; 2:站点自提; 3送货上门]
  13. * @property int $status 状态[0禁用 1启用 -1删除]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. */
  17. class CommunityGoodsSetting extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_community_goods_setting}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'goods_id', 'enable', 'status', 'created_at', 'updated_at', 'enable_refund'], 'integer'],
  33. [['supported_logistics'], 'string'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => '商城id',
  44. 'goods_id' => '商品id',
  45. 'enable' => '是否开启社区社区团购[0关闭,1开启]',
  46. 'supported_logistics' => '支持物流方式[1:快递配送; 2:站点自提; 3送货上门]',
  47. 'status' => '状态[0禁用 1启用 -1删除]',
  48. 'created_at' => '创建时间',
  49. 'updated_at' => '修改时间',
  50. ];
  51. }
  52. public static function setData(array $params)
  53. {
  54. try {
  55. $model = self::findOne(['mall_id' => $params['mall_id'], 'goods_id' => $params['goods_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  56. if (empty($model)) {
  57. $model = new self();
  58. $model->loadDefaultValues();
  59. }
  60. if (!$model->load($params, '') || !$model->save()) {
  61. throw new \Exception($model->getErrorMessage());
  62. }
  63. return $model;
  64. } catch (\Exception $e) {
  65. self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile();
  66. return false;
  67. }
  68. }
  69. /**
  70. * 商品是否开启社区团购
  71. * @param $mall_id
  72. * @param $goods_id
  73. * @return bool
  74. */
  75. public static function getEnable($mall_id, $goods_id)
  76. {
  77. return self::find()
  78. ->where(['status' => StatusEnum::ENABLED, 'goods_id' => $goods_id, 'enable' => StatusEnum::ENABLED, 'mall_id' => $mall_id])
  79. ->exists();
  80. }
  81. }