| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace addons\CardSecret\common\models;
- use addons\CardSecret\common\enums\CardSecretEnum;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\models\mall\MallAddons;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_CardSecret_goods}}".
- *
- * @property int $id
- * @property string|null $cate_id 绑定分类ID
- * @property int|null $goods_id 商品ID
- * @property int|null $status 状态(-1是已删除,0是禁用,1是正常)
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- * @property int|null $mall_id 商城ID
- */
- class CardSecretGoods extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_card_secret_goods}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['goods_id', 'status', 'created_at', 'updated_at', 'mall_id','cate_id'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'cate_id' => '绑定分类ID',
- 'goods_id' => '商品ID',
- 'status' => '状态(-1是已删除,0是禁用,1是正常)',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'mall_id' => '商城ID',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/5/7 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return string
- */
- public static function setGoodsData($mall_id,$goods_id,$params){
- try{
- $model = self::findOne(['goods_id'=>$goods_id,'mall_id'=>$mall_id,'status' => StatusEnum::ENABLED]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- $model->mall_id = $mall_id;
- $model->goods_id = $goods_id;
- $model->cate_id = $params['cate_id'];
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @Author: ltm
- * @DateTime: 2022/5/12 0012 17:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public static function getGoodSetting($params)
- {
- // 后台页面组件展示
- if ($params['type'] == 'show_component') {
- return [
- 'component' => 'com-card-secret',
- 'path' => Yii::$app->basePath . '/../addons/CardSecret/backend/views/goods',
- ];
- } else {
- try {
- if (empty($params['setting'][CardSecretEnum::ADDONSNAME])) return true;
- $setting = $params['setting'][CardSecretEnum::ADDONSNAME];
- // 数据保存
- $res = CardSecretGoods::setGoodsData($params['mall_id'], $params['goods_id'], $setting);
- if ($res === false) throw new Exception(CardSecretGoods::getStaticError());
- return true;
- } catch (Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
- /**
- * @Author: ltm
- * @DateTime: 2022/5/12 0012 12:45
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public static function isInstall(array $params){
- //插件判断 是否显示卡密信息
- $card_secret = MallAddons::isInstall($params['mall_id'], CardSecretEnum::ADDONSNAME);
- $data = $params['order'];
- if($card_secret){
- $card_secret = CardSecretUse::getOne([['mall_id' =>$params['mall_id'],'order_id'=> $params['order']['id']]],true);
- if($card_secret){
- $data[CardSecretEnum::ADDONSNAME]['is_show_card_secret'] = 1;
- }else{
- $data[CardSecretEnum::ADDONSNAME]['is_show_card_secret'] = 0;
- }
- }
- return $data;
- }
- }
|