| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace addons\Mch\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_mch_goods_model".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $mch_id
- * @property int $goods_id 商品id
- * @property string|null $content 内容
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class MchGoodsModel extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_mch_goods_model}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mch_id', 'goods_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['content'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'mch_id' => 'Mch ID',
- 'goods_id' => '商品id',
- 'content' => '内容',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['mall_id'])&&!empty($params['mch_id'])&&!empty($params['goods_id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'mch_id' => $params['mch_id'], 'goods_id' => $params['goods_id'], 'status' => [StatusEnum::ENABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile();
- return false;
- }
- }
- /**
- * 商品是否参与渠道分红
- *
- * @param int $mallId
- * @param int $mchId
- * @param int $goodsId
- *
- * @return bool
- */
- public static function isParticipateAgent(int $mallId, int $mchId, int $goodsId)
- {
- $content = MchGoodsModel::find()
- ->where([
- 'mch_id' => $mchId,
- 'mall_id' => $mallId,
- 'goods_id' => $goodsId,
- 'status' => StatusEnum::ENABLED
- ])
- ->select('content')
- ->scalar();
- $content = json_decode($content, true);
- $agent = json_decode($content['Agent'], true);
- return !isset($agent['distribution_setting']['is_participate']) || !empty($agent['distribution_setting']['is_participate']);
- }
- }
|