request->isAjax) { if (\Yii::$app->request->isGet) { //商品列表筛选 $get = Yii::$app->request->get(); $rules = [ [['goods_id', 'is_chanjet_addons', 'limit'], 'integer'], [['goods_name', 'sort_field'], 'string'], [['type'], 'in', 'range' => ['all', 'onsale', 'offline', 'sell-out', 'stock-lack']], [['sort_type'], 'in', 'range' => ['asc', 'desc']], [['cats'], 'each', 'rule' => ['integer']], [['start', 'end', 'update_start', 'update_end'], 'datetime', 'format' => 'php:Y-m-d H:i:s'], [['goods_type'], 'safe'], ]; $res = Yii::$app->services->validate->validate($get, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [['mall_id' => $this->mall['id'], 'mch_id' => $this->admin->mch_id, 'g.status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]; //过滤插件商品 $where[]=[ 'or', ['!=','g.goods_source','Aiyunuo'], ['is', 'g.goods_source', new \yii\db\Expression('null')] ]; // $where[] = ['!=', 'g.goods_name', '代客下单插件商品']; // 筛选 !empty($get['start']) && $where[] = ['>=', 'g.created_at', strtotime($get['start'])]; !empty($get['end']) && $where[] = ['<=', 'g.created_at', strtotime($get['end'])]; !empty($get['update_start']) && $where[] = ['>=', 'g.updated_at', strtotime($get['update_start'])]; !empty($get['update_end']) && $where[] = ['<=', 'g.updated_at', strtotime($get['update_end'])]; !empty($get['goods_name']) && $where[] = ['like', 'g.goods_name', '%' . trim($get['goods_name']) . '%', false]; if(!empty($get['cats'])){ $goods_cate_relate_list = GoodsCateRelate::lists(['where'=>[['cate_id'=>$get['cats']]]]); $goods_ids = array_column($goods_cate_relate_list,'goods_id'); $where[] = ['in', 'g.id', $goods_ids]; } !empty($get['goods_id']) && $where[] = ['=', 'g.id', $get['goods_id']]; if (!empty($get['goods_type'])) { if (strpos($get['goods_type'], ',') !== false) { $get['goods_type'] = explode(',', $get['goods_type']); } $where[] = ['g.goods_type' => $get['goods_type']]; } if (!empty($get['type'])) { switch ($get['type']) { case 'onsale': $where[] = ['=', 'g.is_on_sale', WhetherEnum::ENABLED]; break; case 'offline': $where[] = ['=', 'g.is_on_sale', WhetherEnum::DISABLED]; break; case 'sell-out': $where[] = ['=', 'g.stock', 0]; break; case 'stock-lack': $where[] = new \yii\db\Expression('`stock` <= `stock_warning`'); break; } } // with $with = ['cats', 'attr']; // 排序 $sort = ''; if (isset($get['sort_field']) && isset($get['sort_type'])) $sort = 'g.' . $get['sort_field'] . ' ' . $get['sort_type']; $sort = !empty($sort) ? $sort . ',g.sort ASC,g.id DESC' : 'g.sort ASC,g.id DESC'; // 畅捷通插件相关 if (!empty($get['is_chanjet_addons'])) { $with[] = 'addonsChanjetRequest'; } $limit = $get['limit'] ?? 10; $select = "g.id, g.goods_name, g.price, g.cost_price, g.unit, g.cover_pic, g.is_on_sale, g.is_attr, g.attr_groups, g.attr_groups, g.status, g.stock, g.virtual_sales, g.goods_type, g.services, g.goods_source, g.check_status, g.check_remark, g.sort, g.created_at, g.stock_warning, g.sales_num"; $params = array('alias' => 'g', 'where' => $where, 'with' => $with, 'limit' => $limit, 'order' => $sort, 'select' => $select); $page_data = Goods::listPage($params, false, true); if ($page_data === false) return $this->error(Goods::getStaticError()); $page_data["export_list"] = Goods::fieldsList(); $goods_marketing_arr = []; if (!empty($page_data['list'])) { $goods_id_arr = array_column($page_data['list'], 'id'); $goods_marketing_list = GoodsMarketing::lists(['where' => [['mall_id' => $this->mall_id], ['goods_id' => $goods_id_arr], ['status' => StatusEnum::ENABLED]], 'select' => 'goods_id,marketing_type']); foreach ($goods_marketing_list as $val) { $goods_marketing_arr[$val['goods_id']][] = $val['marketing_type']; } $mall = $this->mall; foreach ($page_data['list'] as &$item) { $addons_name = ''; if (isset($goods_marketing_arr[$item['id']])) { foreach ($goods_marketing_arr[$item['id']] as $value) { if (is_string(AddonsEnum::getAddonsNameMap($value))) $addons_name .= AddonsEnum::getAddonsNameMap($value) . ','; } $addons_name = trim($addons_name, ','); } $item['addons_name'] = $addons_name; $item['h5_url'] = MallHost::getHost($this->mall_id,'h5_url'). '/#/plugins/pages/goods/detail?sign=' .$mall['mall_sign'].'&proId='.$item['id']; } } // 判断是否有安装支付宝商家券插件 $page_data['alipay_mini_app_id'] = null; $page_data['mall_sign'] = $this->mall['mall_sign']; if (MallAddons::isInstall($this->mall_id,AddonsEnum::ADDONS_NAME_ALIPAY_MCH_COUPON)) { $page_data['alipay_mini_app_id'] = \Yii::$app->services->setting->mall->get($this->mall_id, 'alipay_mini.app_id'); $page_data['alipay_mini_app_id'] = !empty($page_data['alipay_mini_app_id']) ? $page_data['alipay_mini_app_id'] : null; } // 则需要展示sku_id $page_data['show_sku_dialog'] = StatusEnum::DISABLED; if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_WANG_DIAN_TONG)) { $page_data['show_sku_dialog'] = StatusEnum::ENABLED; } // 是否显示同步商品到门店的按钮 $page_data['synchronize_goods_dialog'] = StatusEnum::DISABLED; if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE)) { $page_data['synchronize_goods_dialog'] = StatusEnum::ENABLED; } // 是否需要设置支付成功后跳转 $page_data['pay_success_jump'] = StatusEnum::DISABLED; if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PAY_SUCCESS_JUMP)) { $pay_jump_config = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_PAY_SUCCESS_JUMP, 'basic'); if (!empty($pay_jump_config['is_enable'])) { $page_data['pay_success_jump'] = intval($pay_jump_config['is_enable_jump']); } } return $this->success('操作成功', $page_data); } else { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } $params = Yii::$app->request->get(); $is_compliance = Yii::$app->services->mall->isOpenComplianceMode($this->mall_id); return $this->render($this->action->id, ['pay_success_jump_component' => MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PAY_SUCCESS_JUMP), 'search_params' => $params, 'is_compliance' => $is_compliance]); } public function actionDel() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } //批量上传 public function actionDelBatch() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); foreach ($form['id'] as $id){ $res = $this->doHandle(['id'=>$id,'type'=>'destroy']); } return $this->success(); } } //批量上下架 public function actionDoOnSaleBatch() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); foreach ($form['id'] as $id){ $this->doHandle(['id'=>$id,'type'=>'is_on_sale','is_on_sale'=>$form['is_on_sale']]); } return $this->success(); } } public function actionDoOnSale() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } public function actionDoSort() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } public function actionDoVirtualSales() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } public function actionDoGoodsName() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } public function actionDoGoodsStock() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); return $this->doHandle($form); } } public function actionDoGoodsAttrStock() { if (\Yii::$app->request->isAjax) { // 商品操作 $form = Yii::$app->request->post(); if ($form['attr_stock']) { $attr_stock_array = array_column($form['attr_stock'], 'stock'); $form['stock'] = array_sum($attr_stock_array); foreach ($form['attr_stock'] as $item) { if ($item['stock'] < 0) { return $this->error('商品库存需大于等于0'); } } } return $this->doHandle($form); } } protected function doHandle($form) { // 商品操作 $rules = [[['id'], 'required'], [['id'], 'integer']]; $type = $form['type'] ?? ''; switch ($form['type']) { case 'sort': //排序 $rules[] = [['sort'], 'required']; break; case 'destroy': //删除 $form['status'] = -1; $rules[] = [['status'], 'required']; break; case 'goods_name': //修改商品名称 $rules[] = [['goods_name'], 'required']; break; case 'is_on_sale': //上下架 $rules[] = [['is_on_sale'], 'required']; $rules[] = [['is_on_sale'], 'in', 'range' => [WhetherEnum::ENABLED, WhetherEnum::DISABLED]]; break; case 'virtual_sales': //虚拟销量 $rules[] = [['virtual_sales'], 'required']; break; case 'goods_stock': //库存 $rules[] = [['stock'], 'required']; $rules[] = [['stock'], 'integer', 'message' => '商品库存必须是整数。']; $rules[] = [ ['stock'], 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => '商品库存需大于等于0' ]; break; case 'attr_stock': //多规格库存 $rules[] = [['attr_stock', 'stock'], 'required']; break; } $res = Yii::$app->services->validate->validate($form, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['mall_id'] = $this->mall['id']; $form['mch_id'] = $this->admin->mch_id; $goods_id = $form['id']; unset($form['id']); $res = Goods::goodsHandle($goods_id, $form); if ($res === false) return $this->error(Goods::getStaticError()); //修改商品的规格 if ($form['status']) { $attr_goods = GoodsAttr::find()->where(['goods_id' => $goods_id])->all(); foreach ($attr_goods as $model) { $model->status = $form['status']; $model->updated_at = time(); $model->update(false); } } //修改商品的规格库存 if ($form['attr_stock']) { foreach ($form['attr_stock'] as $attr_stock) { $attr_goods = GoodsAttr::find()->where(['id' => $attr_stock['id']])->one(); $attr_goods->stock = $attr_stock['stock']; $attr_goods->updated_at = time(); $attr_goods->update(false); } } if ($type == 'goods_stock') { $goods = Goods::find()->where(['id' => $goods_id, 'mall_id' => $this->mall['id']])->asArray()->one(); $res = GoodsAttr::setAttr($goods_id, $goods); if ($res === false) throw new \Exception('设置货品失败:' . GoodsAttr::getStaticError()); } // //编辑商品触发 $event = new GoodsEditEvent($this->mall['id']); $data['goods_id'] = $goods_id; $data['mall_id'] = $this->mall['id']; $data['wait_del_attr_id_arr'] = ''; $data['type'] = $type; if (isset($form['is_on_sale'])) $data['is_on_sale'] = $form['is_on_sale']; Yii::$app->services->events->dispatch($event, $data, $event->listeners); return $this->success(); } /** *商品导出 * @Author ltm * @DateTime 2021-12-02 11:16:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionExportExcel() { if (\Yii::$app->request->isPost) { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $filename = '商品列表-' . date('YmdHis') . '_' . rand(10000, 99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_GOODS, Goods::class, 'exportHandle', $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } /** * 商品首页 * @Author ltm * @DateTime 2021-11-17 11:16:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionSearch() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { //商品列表筛选 $get = Yii::$app->request->get(); $rules = [ [['keyword', 'goods_source'], 'string'], [['is_partake_goods', 'goods_id','screen_main_goods','req','reqId','price','sudoku_is_attr', 'exclude_goods_ids'], 'safe'], [['goods_type', 'is_achievement'],'safe'] ]; $res = Yii::$app->services->validate->validate($get, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $sort = !empty($sort) ? $sort . ',sort ASC,id DESC' : 'sort ASC,id DESC'; $data = Goods::getPaginationList(15, function($query) use ($get) { if ($get['is_achievement'] == 1) { $where = [ 'and', [ 'mall_id' => $this->mall_id, 'is_on_sale' => 1, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], ] ]; } else { $where = [ 'and', [ 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id, 'is_on_sale' => 1, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], ] ]; } isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]]; if(!empty($get['price'])){ $where[]=['price'=>trim($get['price'])]; } if (isset($get['sudoku_is_attr'])) { // 九宫格插件关联商品。只显示单规格 $where[] = ['is_attr' => 0]; } if (isset($get['goods_id']) && !empty($get['goods_id'])) { $where[] = ['!=', 'id', $get['goods_id']]; } if (isset($get['exclude_goods_ids']) && !empty($get['exclude_goods_ids'])) { $where[] = ['not in', 'id', $get['exclude_goods_ids']]; } if (isset($get['goods_type']) && !empty($get['goods_type'])) { if(is_array($get['goods_type'])){ $where[] = ['in', 'goods_type', $get['goods_type']]; } elseif (is_string($get['goods_type'])) { $where[] = ['goods_type' => explode(',', $get['goods_type'])]; }else{ $where[] = ['=', 'goods_type', $get['goods_type']]; } } if (!empty($get['goods_source'])) { if ($get['goods_source'] === 'Main') { $where[] = ['=', 'mch_id', 0]; $where[] = ['=', 'goods_source', '']; } elseif ($get['goods_source'] === 'Mch') { $where[] = ['>', 'mch_id', 0]; } else { $where[] = ['=', 'goods_source', $get['goods_source']]; } } if (isset($get['is_partake_goods'])) { $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DOUBLE_COPY); if ($is_install) { //只返回二二复制(佣金模式)的商品 $partake_goods_list = \addons\DoubleCopy\common\models\DoubleCopyCommissionItemSetting::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['is_partake' => '1'], ['commission_type' => 'commission'], ['status' => [StatusEnum::ENABLED]]], 'index' => 'item_id']); if (!empty($partake_goods_list)) { $partake_goods_ids = array_column($partake_goods_list, 'item_id'); $where[] = ['in', 'id', $partake_goods_ids]; } //过滤已经设置在二二复制贡献补贴的商品 $not_in_goods_list = \addons\DoubleCopyCommitmentAward\common\models\DoubleCopyCommitmentAwardGoodsSetting::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['status' => [StatusEnum::ENABLED]]], 'select' => 'goods_id']); if (!empty($not_in_goods_list)) { $not_in_goods_ids = array_column($not_in_goods_list, 'goods_id'); $where[] = ['not in', 'id', $not_in_goods_ids]; } } } $query->where($where); }, $sort); return $this->success('操作成功', $data); } } return $this->render($this->action->id); } /** * 商品编辑 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionEdit() { $is_reserve_type = $this->reserveGoodsType(); if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { // 反显商品信息 $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [[['id'], 'integer']]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $detail = isset($get['id']) ? Goods::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]], true, ['cats', 'attr', 'extra', 'reserve', 'reserve.skus', 'reserve.skus.times', 'reserve.skus.times.timeSpec', 'searchAddress']) : []; if (isset($get['id'])) { $detail['freight_type'] = !empty($detail['freight_type']) ? explode(',', $detail['freight_type']) : []; } else { $detail['freight_type'] = [1]; } $detail['services'] = !empty($detail['services']) ? explode(',', $detail['services']) : []; $detail['labels'] = !empty($detail['labels']) ? explode(',', $detail['labels']) : []; $detail['attr_groups'] = !empty($detail['attr_groups']) ? json_decode($detail['attr_groups'], true) : []; $detail['bannar_pic'] = !empty($detail['bannar_pic']) ? json_decode($detail['bannar_pic'], true) : []; $detail['attr_groups_format'] = !empty($detail['attr_groups_format']) ? json_decode($detail['attr_groups_format'], true) : []; $detail['area_limit'] = !empty($detail['area_limit']) ? json_decode($detail['area_limit'], true) : []; $detail['cats'] = !empty($detail['cats']) ? $detail['cats'] : []; if(!empty($detail['searchAddress'])){ $detail['searchAddress']['addressIdsMap'] = GoodsSearchAddress::formatAddressIds($detail['searchAddress']['province_id'],$detail['searchAddress']['city_id'], $detail['searchAddress']['district_id']); $detail['searchAddress']['town_id'] = $detail['searchAddress']['town_id'] > 0 ? $detail['searchAddress']['town_id'] : ''; }else{ $detail['searchAddress'] = []; } // 预约商品字段处理 if (!empty($detail['reserve'])) { $reserve = &$detail['reserve']; !empty($reserve['reserve_date']) && $reserve['reserve_date'] = json_decode($reserve['reserve_date'], true); !empty($reserve['reserve_time_slot']) && $reserve['reserve_time_slot'] = json_decode($reserve['reserve_time_slot'], true); !empty($reserve['reserve_time_slot_price']) && $reserve['reserve_time_slot_price'] = json_decode($reserve['reserve_time_slot_price'], true); !empty($reserve['service_type']) && $reserve['service_type'] = json_decode($reserve['service_type'], true); !empty($reserve['reserve_week']) && $reserve['reserve_week'] = explode(',',$reserve['reserve_week']); if (!empty($reserve['skus'])) { foreach($reserve['skus'] as &$sku){ $signId = $sku['sign_id']; $sku['attr_list'] = $detail['attr_groups_format'][$signId] ?? []; !empty($sku['reserve_date']) && $sku['reserve_date'] = json_decode($sku['reserve_date'], true); !empty($sku['reserve_week']) && $sku['reserve_week'] = explode(',',$sku['reserve_week']); !empty($sku['reserve_time_slot']) && $sku['reserve_time_slot'] = json_decode($sku['reserve_time_slot'], true); !empty($sku['reserve_time_slot_price']) && $sku['reserve_time_slot_price'] = json_decode($sku['reserve_time_slot_price'], true); } } $reserve['cancel_rule'] = $reserve['cancel_rule'] ? json_decode($reserve['cancel_rule'], true) : []; } // 新建商品设置默认属性 if (empty($get['id'])) $detail = Goods::getDefaultSetting($this->mall_id, $detail); //新增商品重量 默认获取qimall_goods_attr表第一个 // if(isset($detail['is_attr'])){ $detail['attr'] = GoodsAttr::formatFormAttr($detail['attr'] ?? [], $detail['attr_groups_format']); $detail['goods_weight'] = isset($detail['attr'][0]['weight']) ? $detail['attr'][0]['weight'] : 0; // } if (isset($detail['extra'])) { $extra = &$detail['extra']; $extra['score_give_setting'] = json_decode($extra['score_give_setting'], true) ?? []; $extra['balance_give_setting'] = json_decode($extra['balance_give_setting'], true) ?? []; $extra['score_deduct_setting'] = json_decode($extra['score_deduct_setting'], true) ?? []; $extra['currency_deduct_setting'] = json_decode($extra['currency_deduct_setting'], true) ?? []; $extra['member_price_setting'] = json_decode($extra['member_price_setting'], true) ?? []; $extra['member_buy_limit_setting'] = json_decode($extra['member_buy_limit_setting'], true) ?? []; $extra['repurchase_setting'] = json_decode($extra['repurchase_setting'], true) ?? []; $extra['digital_give_setting'] = json_decode($extra['digital_give_setting'], true) ?? []; $extra['symptom_list'] = json_decode($extra['symptom_list'], true) ?? []; $extra['description_list'] = json_decode($extra['description_list'], true) ?? []; } if (!isset($extra['score_give_setting']['settlement'])) $extra['score_give_setting']['settlement'] = 1; if(empty($extra['score_deduct_setting'])){ $extra['score_deduct_setting'] = [ 'code'=>'score', 'name'=> '积分', 'is_enable'=> 0, 'deduct_num'=> 0, 'deduct_type'=> 1, ]; } if(empty($extra['balance_give_setting'])){ $extra['balance_give_setting'] = [ 'code'=>'balance', 'name'=>'余额', 'give_num'=>0, 'give_type'=>1, 'settlement'=>0, ]; } if (!empty($extra['member_alone_buy_limit_setting'])) { $extra['member_alone_buy_limit_setting'] = json_decode($extra['member_alone_buy_limit_setting'], true); } else { $extra['member_alone_buy_limit_setting'] = []; } unset($detail['attr_groups_format']); // 获取分类 $cond = [['mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]]; // $cates = GoodsCate::getCates($cond,[],true,'id,name,parent_id'); // $cates = GoodsCate::getTreeCate($cates); // 获取商品标签 $labels = GoodsLabel::getLabels($cond, [], true, 'id,title,sub_title'); $services = GoodsService::getServices($cond, [], true, 'id,name'); $templates = GoodsDecorationTemplate::getTemplates([['mall_id' => $this->mall_id]], [], true, 'id, name') ?? []; $goods_template_id = ''; if (isset($detail['id'])) { $templates_arr = array_column($templates, 'id'); $goods_template = GoodsTemplateRelation::getOne([['mall_id' => $this->mall_id], ['goods_id' => $detail['id']], ['status' => StatusEnum::ENABLED]], true, [], false, 'id, template_id'); $goods_template_id = $goods_template ? (in_array($goods_template['template_id'], $templates_arr) ? $goods_template['template_id'] : $goods_template_id) : $goods_template_id; } $detail['goods_template_id'] = $goods_template_id; // 用户等级 $levels = UserLevel::getUserLevel([['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], [], true, 'id,level,name'); $levels = array_merge([['level' => 0, 'name' => '普通用户']], $levels); // 运费模板 $freight_rules = FreightRules::getFreightRules($cond, [], true, 'id,name'); // 商品类型 $goods_type = GoodsTypeEnum::getGoodsType(); // 判断是否需要移除预约商品 if ($is_reserve_type == StatusEnum::DELETE) { unset($goods_type[GoodsTypeEnum::GoodsTypeReserved]); } if (!empty($detail['attr'])) { if ($detail['is_attr'] == 0) { $detail['goods_no'] = $detail['attr'][0]['goods_no']; } } // 广告模板是否显示 $detail['alipay_mini_app_id'] = null; if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_ALIPAY_MCH_COUPON)) { $detail['alipay_mini_app_id'] = \Yii::$app->services->setting->mall->get($this->mall_id, 'alipay_mini.app_id'); } // // 商品营销配置+会员权益 // $setting = GoodsExtra::getExtraSetting($this->mall_id, $get['id']); // $marketing_setting = $setting['marketing']; // $member_setting = GoodsExtra::getReferencePrice($this->mall_id, $setting['member'], $detail['attr']); $detail['pay_limit']=json_decode($detail['pay_limit'],true)??[]; $detail['pay_limit']=is_array($detail['pay_limit'])?$detail['pay_limit']:[]; $digital = MallSetting::conf($this->mall_id, 'digital.is_enable'); $detail['digital_name'] = $digital ? MallSetting::conf($this->mall_id, 'digital.name') : ''; $detail['is_show_attr'] = isset(Yii::$app->params['is_show_attr']) ? Yii::$app->params['is_show_attr'] : false; // 公共调用 $goods_association = GoodsAssociation::getOne([['goods_id'=>$detail['id']],['status'=>StatusEnum::ENABLED]],true); $extra1_goods_list = []; $extra2_goods_list = []; $extra1_goods_id = []; $extra2_goods_id = []; if($goods_association){ $extra1_goods_id = json_decode($goods_association['extra1_goods_id'],true); $extra2_goods_id = json_decode($goods_association['extra2_goods_id'],true); $extra1_goods_list = Goods::lists(['where'=>[['id'=>$extra1_goods_id]],'select'=>'id as goods_id,price,status,stock as goods_stock,goods_name,cover_pic'],true); $extra2_goods_list = Goods::lists(['where'=>[['id'=>$extra2_goods_id]],'select'=>'id as goods_id,price,status,stock as goods_stock,goods_name,cover_pic'],true); } $detail['extra1_goods_id'] = $extra1_goods_id; $detail['extra2_goods_id'] = $extra2_goods_id; if (is_numeric($detail['goods_no'])) { $detail['goods_no'] = $detail['goods_no'] . ' '; } //判断是否安装云盟店插件 $detail['is_install_yunmeng'] = 0; if(MallAddons::isInstall($this->mall_id,'Yunmeng')){ $yunmeng_setting = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_YUNMENG, 'basic'); if ($yunmeng_setting['is_enable'] == 1) { $detail['is_install_yunmeng'] = 1; } } // 商品说明 $descriptionTemplateService = new DescriptionTemplateService(['mall_id' => $this->mall_id]); $descriptionTemplateList = $descriptionTemplateService->selectList(); if (!empty($detail['extra']['description_template_id'])) { $templateFields = $descriptionTemplateList[$detail['extra']['description_template_id']]['fields'] ?? []; $descriptionList = []; $descriptionMap = array_column($detail['extra']['description_list'], 'value', 'field'); foreach ($templateFields as $field) { $descriptionList[] = ['field' => $field, 'value' => $descriptionMap[$field] ?? '']; } $detail['extra']['description_list'] = $descriptionList; } // 是否安装云处方插件 $detail['is_enable_cloud_prescription'] = false; if(MallAddons::isInstall($this->mall_id,AddonsEnum::ADDONS_NAME_CLOUD_PRESCRIPTION)){ $cloudPrescriptionService = new \addons\CloudPrescription\common\services\SettingService(['mall_id' => $this->mall_id]); $detail['is_enable_cloud_prescription'] = $cloudPrescriptionService->isEnable(); } return $this->success('操作成功', compact('detail', 'labels', 'services', 'levels', 'goods_type', 'freight_rules', 'templates','extra1_goods_list','extra2_goods_list', 'descriptionTemplateList')); } else { // 编辑商品 $form = json_decode(Yii::$app->request->post('form'), true); $form['mall_id'] = $this->mall['id']; $form['mch_id'] = $this->admin->mch_id; if(!empty($form['id'])){ if(MallAddons::isInstall($this->mall_id,'CloudStock')){ $res = \addons\CloudStock\common\models\CloudStockGoods::findOne(['mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED,'goods_id'=>$form['id']]); if(!empty($form['is_attr'])&&!empty($res)){ return $this->error('该商品是云库存商品,不允许修改成多规格'); } } } if(isset($form['goods_no'])) $form['goods_no'] = (string)$form['goods_no']; $res = Goods::setData($form); if ($res === false) return $this->error(Goods::getStaticError()); //添加商品触发 if (empty($form['id'])) { $event = new GoodsCreateEvent($this->mall['id']); $data['goods_id'] = $res['id']; $data['mall_id'] = $this->mall['id']; Yii::$app->services->events->dispatch($event, $data, $event->listeners); } return $this->success('操作成功'); } } // 公共调用 $install_addons = GlobalInvoke::exec(GlobalInvoke::GOODS_DETAIL_EDIT, $this->mall_id, [ 'type' => 'show_component', 'mall_id' => $this->mall_id, ]); $smart_form_addons = []; $valet_order_addons = []; $community_addons = []; foreach ($install_addons as $key => $val) { $component = $val['component'] ?? ''; if ($component == 'com-smartform-goods') { $smart_form_addons = $val; unset($install_addons[$key]); } if ($component == 'com-community-goods') { $community_addons = $val; unset($install_addons[$key]); } if ($component == 'com-valet-order-goods') { $valet_order_addons = $val; unset($install_addons[$key]); } } return $this->render($this->action->id, ['components' => $install_addons, 'smart_form_components' => $smart_form_addons, 'community_components' => $community_addons, 'valet_order_components' => $valet_order_addons, 'is_reserve_type' => $is_reserve_type,'mall_id' => $this->mall_id]); } /** * 预约商品 * @return int -1两个插件都没有安装,0仅限预约商品,1仅限预约服务,2商品/服务 */ protected function reserveGoodsType() { // 是否有安装家政服务 $is_install_home_making = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_HOME_MAKING); // 是否有安装预约服务 $is_install_reserve_service = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_RESERVATION_SERVICE); $diff = $is_install_home_making <=> $is_install_reserve_service; if ($diff < 0) { // 如果没有安装预约服务 return 1; } else if ($diff == 0 && $is_install_home_making == 0) { // 如果两个都没有安装 return -1; } else if ($diff == 0) { // 两个都有安装 return 2; } else { // 如果仅安装了家政服务 return 0; } } /** * 批量导入商品 * @return mixed|string|void */ public function actionImportGoods() { set_time_limit(0); if (\Yii::$app->request->isAjax) { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['current_num'], 'required'], [['file'], 'file', 'extensions' => ['csv']], [['file_path'], 'string'], [['sync'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; if (!empty($params['sync'])) { $res = Goods::importGoodsSync($params); } else { $res = Goods::importGoods($params); } if ($res === false) return $this->error(Goods::getStaticError()); if (empty($res['fail_counts'])) return $this->success('操作成功', $res); if (!empty($res['fail_counts'])) return $this->error('导入失败' . $res['fail_counts'] . '条'); } else { return $this->render($this->action->id); } } /** * 导入日志记录 * @return mixed|void */ public function actionGetGoodsImportLog() { $params = \Yii::$app->request->get(); $params['where'] = [ ['mall_id' => $this->mall_id], ['source' => Goods::class] ]; $params['order'] = 'id desc'; $data = ImportLog::listPage($params, false, true); if (!empty($data['list'])) { foreach ($data['list'] as &$v) { $v['url'] = ''; if ($v['fail_counts']) $v['url'] = \Yii::$app->urlManager->createUrl(['mall/goods/export-fail', 'import_log_id' => $v['id']]); } } return $this->success('操作成功', $data); } /** * 会员批量导入模板下载 */ public function actionGoodsBatchSendModel() { $csv = new CsvExport(); $file_name = '商品批量导入模板-' . date('YmdHis', time()); $head_list = array_column(GoodsImportEnum::HEAD_LIST, 'field_name'); return $csv->export([], $head_list, $file_name); } /** * 导出失败日志 */ public function actionExportFail() { ImportFailLog::exportFailLog(\Yii::$app->request->get()); } /** * 商品服务首页 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionService() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $keyword = Yii::$app->request->get('keyword', ''); $where = [['mall_id' => $this->mall['id'], 'mch_id' => $this->admin->mch_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]; $limit = Yii::$app->request->get('limit', $this->pageSize); $keyword && $where[] = ['like', 'name', $keyword . '%', false]; $order = 'sort asc,id desc'; $params = compact('where', 'order', 'limit'); $page_data = GoodsService::listPage($params, false); return $this->success('操作成功', $page_data); } else { $form = Yii::$app->request->post(); $rules = [[['id'], 'required'], [['id'], 'integer']]; switch ($form['type']) { case 'sort': //排序 $rules[] = [['sort'], 'required']; break; case 'destroy': //删除 $form['status'] = -1; $rules[] = [['status'], 'required']; break; case 'default': //设置默认值 $rules[] = [['is_default'], 'required']; break; } $res = Yii::$app->services->validate->validate($form, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['mall_id'] = $this->mall['id']; $form['mch_id'] = $this->admin->mch_id; $res = GoodsService::setData($form); if ($res === false) return $this->error(GoodsService::getStaticError()); return $this->success('操作成功', $form); } } return $this->render($this->action->id); } /** * 商品服务编辑 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionServiceEdit() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [[['id'], 'required'], [['id'], 'integer']]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $detail = GoodsService::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]], true); return $this->success('操作成功', compact('detail')); } else { $form = Yii::$app->request->post('form'); $res = Yii::$app->services->validate->validate($form, [ [['name'], 'required'], [['id'], 'integer'], [['is_default', 'sort', 'remark'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['mall_id'] = $this->mall['id']; $form['mch_id'] = $this->admin->mch_id; $res = GoodsService::setData($form); if ($res === false) return $this->error(GoodsService::getStaticError()); return $this->success('操作成功'); } } return $this->render($this->action->id); } /** * 商品标签首页 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionLabel() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $keyword = Yii::$app->request->get('keyword', ''); $where = [['mall_id' => $this->mall['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]; $keyword && $where[] = ['like', 'title', $keyword . '%', false]; $order = 'sort asc,created_at desc'; $params = compact('where', 'order'); $page_data = GoodsLabel::listPage($params, false); return $this->success('操作成功', $page_data); } else { $form = Yii::$app->request->post(); $rules = [[['id'], 'required'], [['id'], 'integer']]; switch ($form['type']) { case 'sort': $rules[] = [['sort'], 'required']; break; case 'destroy': $form['status'] = -1; $rules[] = [['status'], 'required']; break; case 'default': $rules[] = [['is_default'], 'integer']; break; } $res = Yii::$app->services->validate->validate($form, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['mall_id'] = $this->mall['id']; $res = GoodsLabel::setData($form); if ($res === false) return $this->error(GoodsLabel::getStaticError()); return $this->success('操作成功', $form); } } return $this->render($this->action->id); } /** * 商品服务编辑 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionLabelEdit() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [[['id'], 'required'], [['id'], 'integer']]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $detail = GoodsLabel::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id]], true); return $this->success('操作成功', compact('detail')); } else { $form = Yii::$app->request->post('form'); $res = Yii::$app->services->validate->validate($form, [ [['title'], 'required'], [['id'], 'integer'], [['sort', 'sub_title'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['mall_id'] = $this->mall['id']; $res = GoodsLabel::setData($form); if ($res === false) return $this->error(GoodsLabel::getStaticError()); return $this->success('操作成功'); } } return $this->render($this->action->id); } /** * 推荐商品列表 * @return mixed|string|void */ public function actionRecommendGoods() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { //商品列表筛选 $get = Yii::$app->request->get(); $where = [['mall_id' => $this->mall['id'], 'mch_id' => $this->admin->mch_id, 'g.status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]; // 筛选 !empty($get['keyword']) && $where[] = ['or', ['like', 'g.goods_name', $get['keyword'] . '%', false], ['=', 'g.id', $get['keyword']]]; $where[] = ['=', 'g.is_on_sale', WhetherEnum::ENABLED]; //去除重复选中的商品 if (in_array($get['type'], ["goods", "order_pay", "order_comment"])) { $data = MallSetting::getConfByGroup($this->mall_id, ["goods", "order_pay", "order_comment"], true); if ($data[$get['type']]['goods_list']['value']) $goods_ids = array_column(json_decode($data[$get['type']]['goods_list']['value']), 'id'); if ($goods_ids) $where[] = ['not in', 'g.id', $goods_ids]; } // 排序 $sort = 'g.id DESC'; if (isset($get['sort_field']) && isset($get['sort_type'])) $sort = 'g.' . $get['sort_field'] . ' ' . $get['sort_type']; $select = 'id,goods_name,cover_pic,price'; $params = array('alias' => 'g', 'where' => $where, 'select' => $select, 'limit' => 10, 'order' => $sort); $page_data = Goods::listPage($params, false, true); if ($page_data === false) return $this->error(Goods::getStaticError()); return $this->success('操作成功', $page_data); } } return $this->render($this->action->id); } /** * 获取商品模式 * @Author: lun * @DateTime: 2021/10/26 0026 11:47 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|string|void */ public function actionGoodsModel() { // 获取组件配置 $addons_setting = AddonsLimit::getGlobalSetting($this->mall_id); $arr = array_keys($addons_setting); //排除推三返一 foreach ($arr as $key) { if($key=='Rebate' || $key == 'RecommendReward') { unset($addons_setting[$key]); } // 因为微信视频小店去除分销员。所以不需要显示商品独立配置 if($key == 'WechatVideoShop') { unset($addons_setting[$key]); } } $first = $arr[0] ?? ''; $addons_list = Addons::lists(['where' => [['name' => $arr]], 'index' => 'name', 'select' => 'title,name']); foreach ($addons_setting as $k => &$item) { $item['is_extra'] = 0; if (isset($addons_list[$k])) { $item['title'] = $addons_list[$k]['title']; } if(in_array($k,[AddonsEnum::ADDONS_NAME_DISTRIBUTION])){ $item['is_extra'] = 1; } } if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { // 商品列表筛选 $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [[['id'], 'required'], [['id'], 'integer']]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 获取商品详情 $detail = Goods::getOne([['id' => $params['id'], 'mall_id' => $this->mall_id, 'mch_id' => $this->admin->mch_id]], true, ['attr']); // 获取配置 $setting_params = ['where' => [['=', 'mall_id', $this->mall_id], ['=', 'item_id', $params['id']], ['=', 'status', StatusEnum::ENABLED]], 'index' => 'commission_type', 'mall_id' => $this->mall_id]; $setting = GlobalInvoke::exec(GlobalInvoke::GOODS_MODEL, $this->mall_id, $setting_params); if (!empty($setting['Community'])) { foreach ($setting['Community'] as $key => $value) { if (!isset($value['calculate_type'])) { $setting['Community'][$key]['calculate_type'] = 0; } } } // dd($setting); // 获取等级 $level_params = ['where' => [['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'level,name', 'order' => 'level asc']; $level_params['mall_id'] = $this->mall_id; $level = GlobalInvoke::exec(GlobalInvoke::GOODS_MODEL_LEVEL, $this->mall_id, $level_params); $commission_type_map = GoodsTypeEnum::getCommissionTypeMap($this->mall_id); // 商品支持的插件分佣币种 $addons_commission_type = GlobalInvoke::exec(GlobalInvoke::INVOKE_COMMISSION_TYPE, $this->mall_id, ['mall_id' => $this->mall_id]); foreach ($addons_commission_type as $type) { $commission_type_map = array_merge($commission_type_map, array_column($type, 'label', 'name')); } $commission_type_map_extra = $commission_type_map; //判断有没有安装积分拓客插件 if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_SCORE_EXPANSION)){ $ScoreExpansionArr = (new ScoreExpansion())->getGoodsModeCommssionType(); foreach($ScoreExpansionArr as $type){ $commission_type_map_extra[$type['name']] = $type['label']; } } if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_ENERGY_VALUE)){ foreach(\addons\EnergyValue\common\enums\EnergyValueEnum::getGoodsModeCommssionType() as $type){ $commission_type_map_extra[$type['name']] = $type['label']; } } // 是否安装并启用额外积分插件 $is_show_additional_score = StatusEnum::DISABLED; if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_POINT_UPPER_LIMIT)) { $is_show_additional_score = (new SettingService())->isEnable($this->mall_id); } return $this->success('操作成功', compact('detail', 'level', 'setting', 'commission_type_map','commission_type_map_extra', 'is_show_additional_score')); } else { $params = Yii::$app->request->post('form'); $res = Yii::$app->services->validate->validate($params, [ [['goods_id'], 'required'], [['goods_id'], 'integer'], [array_keys($addons_setting), 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $trans = Yii::$app->db->beginTransaction(); try { // 初始化保存参数 $base_params = ['mall_id' => $this->mall_id, 'item_id' => $params['goods_id']]; foreach ($addons_setting as $name => $addon) { if (!empty($params[$name])) { $model = new $addon['class']; $res = $model::setData($base_params, Json::decode($params[$name], true)); if ($res == false) throw new \Exception($model->getErrorMessage()); } } $trans->commit(); return $this->success("保存成功"); } catch (\Exception $e) { $trans->rollBack(); return $this->error("保存失败,msg=" . $e->getMessage()); } } } // dd($addons_setting, $addons_setting["BossBonus"]['title']); return $this->render($this->action->id, ['addons_setting' => $addons_setting, 'first' => $first]); } /** * @desc:商品优惠券独立设置查询列表 * @Author: hua * @Date: 2021/12/3 * @Time: 15:07 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionCouponList() { $params = Yii::$app->request->post(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['status' => StatusEnum::ENABLED]; // $where[] = ['is_gift'=>2]; if (!empty($params['coupon_id'])) $where[] = ['id' => $params['coupon_id']]; if (!empty($params['keyword'])) $where[] = ['like', 'name', $params['keyword'] . '%', false]; $params['where'] = $where; $list = AddonsCoupon::listPage($params); $list['appoint_type_map'] = AddonsCouponEnum::getAppointTypeMap(); if (!empty($list['list'])) { foreach ($list['list'] as &$item) { $item['coupon_id'] = $item['id']; } } return $this->success('操作成功', $list); } /** * @return mixed|null */ public function actionSku() { $params = Yii::$app->request->get(); $where[] = ['status' => StatusEnum::ENABLED]; $where[] = ['goods_id' => $params['id']]; $ret = GoodsAttr::lists([ 'where' => $where, 'order' => 'id asc' ]); if (!empty(GoodsAttr::getStaticError())) return $this->error(GoodsAttr::getStaticError()); return $this->success('获取成功', $ret); } /** * 同步商品到门店 */ public function actionSyncGoodsStore(){ try{ $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['selected_goods_ids', 'sync_type'], 'required'], [['selected_store_ids'], 'safe'] ]); if ($res === false) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $handler_class = \addons\Store\common\models\StoreGoods::class; TaskHelper::pushTaskQueue(RabbitMqEnum::EXCHANGE_TASK,RabbitMqEnum::TASK_QUEUE,$params,$handler_class,'syncMallGoods',function(AMQPMessage $message){ // 生产错误 Yii::error('发送异步任务失败'); }); return $this->success('同步成功'); }catch(\Exception $e){ return $this->error($e->getMessage()); } } /** * @Description: 复制商品 * @Author: zsan * @DateTime 2023-05-31 17:00:50 * @return \yii\web\Response */ public function actionCopyGoods(){ try{ $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id'], 'required'], ]); if ($res === false) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $goods = Goods::findOne(['id' => $params['id'], 'mall_id' => $this->mall_id]); if(!$goods) throw new \Exception('商品id参数错误'); $source_goods = $goods['attributes']; unset($source_goods['id']); if(empty($source_goods['services'])){ $source_goods['services'] = []; }else{ $source_goods['services'] = explode(',', $source_goods['services']); } if(empty($source_goods['labels'])){ $source_goods['labels'] = []; }else{ $source_goods['labels'] = explode(',', $source_goods['labels']); } if(empty($source_goods['freight_type'])){ $source_goods['freight_type'] = []; }else{ $source_goods['freight_type'] = explode(',', $source_goods['freight_type']); } !empty($source_goods['attr_groups']) && $source_goods['attr_groups'] = json_decode($source_goods['attr_groups'], true); !empty($source_goods['bannar_pic']) && $source_goods['bannar_pic'] = json_decode($source_goods['bannar_pic'], true); !empty($source_goods['area_limit']) && $source_goods['area_limit'] = json_decode($source_goods['area_limit'], true); !empty($source_goods['pay_limit']) && $source_goods['pay_limit'] = json_decode($source_goods['pay_limit'], true); $extra = $goods->extra ? ArrayHelper::toArray($goods->extra) : []; if(isset($extra['goods_id'])) unset($extra['goods_id']); isset($extra['member_buy_limit_setting']) && $extra['member_buy_limit_setting'] = json_decode($extra['member_buy_limit_setting'], true); $source_goods['extra'] = $extra; $cats = $goods->cats ? ArrayHelper::toArray($goods->cats) : []; $source_goods['cats'] = array_column($cats, 'id') ?? []; if ($goods['is_attr'] == 1) { $temp_attrs = ArrayHelper::toArray($goods->attr); $attr_groups = $goods['attr_groups']; $attr_groups = !empty($attr_groups) ? json_decode($attr_groups, true) : []; $attr = []; foreach ($temp_attrs as $val) { unset($val['id']); unset($val['goods_id']); $sku_group_name = explode(',', $val['name']); $attr_list = []; foreach($sku_group_name as $name){ $name_arr = explode(':', $name); foreach($attr_groups as $group){ if($group['attr_group_name'] == $name_arr[0]){ foreach($group['attr_list'] as $v){ if($v['attr_name'] == $name_arr[1]){ $attr_list[] = [ 'attr_id' => $v['attr_id'], 'attr_name' => $v['attr_name'], 'pic_url' => '', 'attr_group_id' => $group['attr_group_id'], 'attr_group_name' => $group['attr_group_name'], ]; break; } } break; } } } $val['attr_list'] = $attr_list; $attr[] = $val; } $source_goods['attr'] = $attr; } $source_goods['copy_id'] = $params['id'] ?? 0; if(!Goods::setData($source_goods)) throw new \Exception(Goods::getStaticError()); return $this->success('复制成功'); }catch(\Exception $e){ return $this->error($e->getMessage()); } } public function actionBatchSetScore(){ try{ $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['selected_goods_ids', 'set_type'], 'required'], [['give_type', 'deduct_type', 'settlement', 'type'], 'integer'], [['give_num', 'deduct_num',], 'number'] ]); if ($res === false) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $goods_extra = GoodsExtra::findAll(['goods_id' => $params['selected_goods_ids'],'status' => StatusEnum::ENABLED]); if($params['set_type'] == 2){ $new = ['give_type' => $params['give_type'], 'give_num' => $params['give_num'], 'settlement' => $params['settlement']]; /** @var GoodsExtra $extra */ foreach($goods_extra as $extra){ $score_give_setting = json_decode($extra->score_give_setting, true); $score_give_setting = array_merge($score_give_setting, $new); $extra->score_give_setting = json_encode($score_give_setting); $extra->save(); } }else if($params['set_type'] == 1){ $new = ['is_enable' => 1,'deduct_type' => $params['deduct_type'],'deduct_num' => $params['deduct_num'], 'type' => $params['type']]; /** @var GoodsExtra $extra */ foreach($goods_extra as $extra){ $score_deduct_setting = $extra->score_deduct_setting ? json_decode($extra->score_deduct_setting, true) : []; if(empty($score_deduct_setting)) $score_deduct_setting = ['code'=>'score', 'name'=>'积分']; $score_deduct_setting = array_merge($score_deduct_setting, $new); $extra->score_deduct_setting = json_encode($score_deduct_setting); $extra->save(); } } return $this->success('设置成功'); }catch(\Exception $e){ return $this->error($e->getMessage()); } } /** * 获取地区 * @return mixed|null */ public function actionRegions() { $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['id'], 'integer'], [['id'], 'required'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $regions = Region::find() ->select('id,name,lng,lat') ->asArray() ->where(['parent_id' => $params['id']]) ->indexBy('id') ->all(); return $this->success('获取成功', $regions); } /** * @Description: 根据地区id获取第一层子级地区信息列表 * @Author: zhngsan * @DateTime 2023-02-08 11:22:11 * @return mixed */ public function actionGetRegions() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $region_id = \Yii::$app->request->get('region_id'); if (empty($region_id)) { return $this->error('参数错误'); } $region = Region::findOne($region_id); if (empty($region)) { return $this->error('地区信息未找到'); } $region_list = Region::find() ->select('id,name,lng,lat') ->where(['parent_id' => $region->id]) ->asArray() ->all(); return $this->success('success', $region_list); } /** * 商品说明列表 * * @return void|string */ public function actionDescriptionTemplate() { if (!$this->request->isAjax) { return $this->render('goods-description-template/index'); } $service = new DescriptionTemplateService(['mall_id' => $this->mall_id]); $this->success('success', $service->list($this->request->get())); } /** * 删除商品说明 * * @return void */ public function actionDelDescriptionTemplate() { $id = $this->request->post('id'); if (!$id) { $this->error('ID不能为空'); return; } $service = new DescriptionTemplateService(['mall_id' => $this->mall_id]); if (!$service->del($id)) { $this->error($service->getError()); return; } $this->success(); } /** * 编辑商品说明 * * @return void|string */ public function actionEditDescriptionTemplate() { if (!$this->request->isAjax) { return $this->render('goods-description-template/edit'); } $service = new DescriptionTemplateService(['mall_id' => $this->mall_id]); if ($this->request->isGet) { $id = $this->request->get('id'); if (!$id) { $this->success(); return; } $this->success('success', $service->detail($id)); return; } $post = $this->request->post(); $rules = [ [['name', 'frontend_name', 'fields'], 'required'], [['id'], 'integer'], [['fields'], 'safe'], [['name', 'frontend_name'], 'string'], ]; $res = Yii::$app->services->validate->validate($post, $rules); if ($res === false) { $this->error(Yii::$app->services->validate->getErrorMessage()); return; } if (!$service->edit($post)) { $this->error($service->getError()); return; } $this->success(); } public function actionSetSkusCode() { $request = Yii::$app->request; if ($request->isAjax && $request->isPost) { try { $post = $request->post(); $res = Yii::$app->services->validate->validate($post, [ [['is_show_code'], 'integer'], [['skus'], 'safe'] ]); if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage()); foreach ($post['skus'] as $key => $value) { $value['is_show_code'] = $post['is_show_code']; GoodsAttr::updateAll(['is_show_code' => $post['is_show_code'], 'spec_no' => $value['spec_no']], ['id' => $value['id']]); } return $this->success('操作成功'); } catch (\Exception $e) { $this->error($e->getMessage()); } } } }