| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- <?php
- namespace addons\Store\backend\controllers;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\models\StoreGoodsAttr;
- use addons\Store\common\models\StoreGoodsCate;
- use addons\Store\common\models\StoreGoodsCateRelate;
- use addons\Store\common\models\StoreGoodsModel;
- use addons\Store\common\services\SyncMallGoodsService;
- use common\enums\AddonsEnum;
- use common\enums\GoodsTypeEnum;
- use common\enums\StatusEnum;
- use common\enums\WhetherEnum;
- use common\globals\GlobalInvoke;
- use common\logic\common\AddonsLimit;
- use common\models\goods\Goods;
- use common\models\goods\GoodsMarketing;
- use common\models\mall\MallAddons;
- use common\models\goods\GoodsAssociation;
- use common\helpers\StringHelper;
- use Yii;
- class StoreGoodsController extends BaseController
- {
- public function actionIndex()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store-goods/index', ['pay_success_jump_component' =>
- MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PAY_SUCCESS_JUMP)]);
- }
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $rules = [
- [['goods_id', 'goods_type'], 'integer'],
- [['store_ids'], 'safe'],
- [['goods_name', 'sort_field'], 'string'],
- [['type'], 'in', 'range' => ['check_adopt', 'check_waiting', 'check_failed']],
- [['sort_type'], 'in', 'range' => ['asc', 'desc']],
- [['cats'], 'each', 'rule' => ['integer']],
- [['start', 'end'], 'datetime', 'format' => 'php:Y-m-d H:i:s']
- ];
- $res = Yii::$app->services->validate->validate($get, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where[] = ['g.mall_id' => $this->mall_id, 'g.status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- $where[] = ['!=', 'g.store_id', 0];
- // 筛选
- isset($get['start']) && $where[] = ['>=', 'g.created_at', strtotime($get['start'])];
- isset($get['end']) && $where[] = ['<=', 'g.created_at', strtotime($get['end'])];
- isset($get['goods_name']) && $where[] = ['like', 'g.goods_name', trim($get['goods_name']) . '%', false];
- if(!empty($get['cats'])){
- $goods_cate_relate_list = StoreGoodsCateRelate::lists(['where'=>[['cate_id'=>$get['cats']]]]);
- $goods_ids = array_column($goods_cate_relate_list,'goods_id');
- $where[] = ['in', 'g.id', $goods_ids];
- }
- isset($get['goods_id']) && $where[] = ['=', 'g.id', $get['goods_id']];
- !empty($get['goods_type']) && $where[] = ['=', 'g.goods_type', $get['goods_type']];
- if (isset($get['type'])) {
- switch ($get['type']) {
- case 'check_adopt':
- $where[] = ['g.check_status' => 1];
- break;
- case 'check_waiting':
- $where[] = ['g.check_status' => 0];
- break;
- case 'check_failed':
- $where[] = ['g.check_status' => 2];
- break;
- }
- }
- if (!empty($get['store_ids'])) {
- $where[] = ['store_id' => $get['store_ids']];
- }
- // 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';
- $params = array('alias' => 'g', 'where' => $where,'with' => $with, 'limit' => 20, 'order' => $sort);
- $page_data = StoreGoods::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');
- $store_ids = array_column($page_data['list'], 'store_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'];
- }
- $stores = Store::find()
- ->select('id,store_name,logo_img')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $store_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- foreach ($page_data['list'] as &$item) {
- $addons_name = '';
- $store = $stores[$item['store_id']] ?? [];
- $item['store_name'] = $store['store_name'] ?? '';
- $item['logo_img'] = $store['logo_img'] ?? '';
- // 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;
- }
- }
- // 是否需要设置支付成功后跳转
- $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 {
- $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
- $goods_auth = $basic['goods_auth'] ?? 0;
- // 商品操作
- $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 'goods_name': //修改商品名称
- $rules[] = [['goods_name'], 'required'];
- break;
- case 'is_on_sale': //上下架
- if ($form['is_on_sale'] == 0) {
- $form['check_status'] = !$goods_auth ? StoreEnum::CHECK_ADOPT : StoreEnum::CHECK_WAITING;
- } else {
- $form['check_status'] = StoreEnum::CHECK_ADOPT;
- }
- $rule = [
- [['is_on_sale', 'check_status'], 'required'],
- [['is_on_sale'], 'in', 'range' => [WhetherEnum::ENABLED, WhetherEnum::DISABLED]],
- ['check_status', 'integer'],
- ];
- $rules = array_merge($rules, $rule);
- 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'];
- $goods_id = $form['id'];
- unset($form['id']);
- $res = StoreGoods::goodsHandle($goods_id, $form);
- if ($res === false) return $this->error(StoreGoods::getStaticError());
- //修改商品的规格
- if (isset($form['status']) && $form['status']) {
- $attr_goods = StoreGoodsAttr::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['status'] == -1) {
- // 五洲供应链商品删除
- SyncMallGoodsService::deleteGoods($goods_id, $this->mall_id);
- }
- return $this->success();
- }
- }
- /**
- * 商品编辑
- * @Author bing
- * @DateTime 2021-08-20 14:49:55
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- public function actionEdit()
- {
- 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']) ? StoreGoods::getOne([[
- 'id' => $get['id'],
- 'mall_id' => $this->mall_id,
- 'status' => StatusEnum::ENABLED,
- ]], true, ['cats', 'attr', 'extra', 'reserve', 'reserve.skus', 'reserve.skus.times', 'reserve.skus.times.timeSpec']) : [];
- $detail['freight_type'] = !empty($detail['freight_type']) ? explode(',', $detail['freight_type']) : [];
- $detail['services'] = !empty($detail['services']) ? explode(',', $detail['services']) : [];
- $detail['labels'] = !empty($detail['labels']) ? explode(',', $detail['labels']) : [];
- $detail['attr_groups'] = json_decode($detail['attr_groups'], true) ?? [];
- $detail['bannar_pic'] = json_decode($detail['bannar_pic'], true) ?? [];
- $detail['attr_groups_format'] = json_decode($detail['attr_groups_format'], true) ?? [];
- $attr_groups_format = $detail['attr_groups_format'] ?? [];
- $detail['area_limit'] = json_decode($detail['area_limit'], true) ?? [];
- $detail['cats'] = $detail['cats'] ?? [];
- $detail['attr'] = StoreGoodsAttr::formatFormAttr($detail['attr'] ?? [], $detail['attr_groups_format']);
- $detail['goods_weight'] = isset($detail['attr'][0]['weight']) ? $detail['attr'][0]['weight'] : 0;
- $detail['package_data'] = !empty($detail['package_data']) ? json_decode($detail['package_data'], true) : [];
- $detail['show_style'] = !empty($detail['show_style']) ? $detail['show_style'] : 1;
- unset($detail['attr_groups_format']);
- $detail['is_sync_goods'] = 0;// 是否为平台同步过来的商品
- $platform_goods_cate = StoreGoods::getPlatformGoodsCate($this->mall_id);
- if($platform_goods_cate){
- $cate_ids = array_column($detail['cats'], 'id');
- if(in_array($platform_goods_cate['id'], $cate_ids)) $detail['is_sync_goods'] = 1;
- }
- // 用户等级
- $levels = [];
- // 运费模板
- $freight_rules = [];
- // 商品类型
- //营销设置
- if (isset($detail['extra'])) {
- $extra = &$detail['extra'];
- $extra['score_give_setting'] = json_decode($extra['score_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['service_fee_setting'] = json_decode($extra['service_fee_setting'], true) ?? ['is_alone' => 0, 'service_fee_ratio' => null];
- //获取服务费比例
- $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
- $extra['platform_service_fee_setting'] = [
- 'service_fee_type' => $basic['service_fee_type'],
- 'max_platform_ratio' => $basic['max_platform_ratio'],
- 'min_platform_ratio' => $basic['min_platform_ratio']
- ];
- }
- if(!isset($extra['score_give_setting']['settlement']))$extra['score_give_setting']['settlement'] = 1;
- if(!isset($extra['score_give_setting']['condition']))$extra['score_give_setting']['condition'] = 0;
- // 预约商品字段处理
- 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'] = $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) : [];
- }
- $goods_association = GoodsAssociation::getOne([['goods_id'=>$detail['id']], 'mall_id' => $this->mall_id, 'store_id' => $detail['store_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 = StoreGoods::lists(['where'=>[['id'=>$extra1_goods_id]],'select'=>'id as goods_id,price,status,stock as goods_stock,goods_name,cover_pic,store_id'],true);
- $extra2_goods_list = StoreGoods::lists(['where'=>[['id'=>$extra2_goods_id]],'select'=>'id as goods_id,price,status,stock as goods_stock,goods_name,cover_pic,store_id'],true);
- }
- $detail['extra1_goods_id'] = $extra1_goods_id;
- $detail['extra2_goods_id'] = $extra2_goods_id;
- $backend_domain = \Yii::$app->services->setting->platform->get('system.backend_url');
- $backend_domain = empty($backend_domain) ? '' : (string)$backend_domain;
- $store_login_url = trim($backend_domain, '/') . '?r=store/client/auth/login&sign=' . $this->mall['mall_sign'];
- return $this->success('操作成功', compact('detail', 'levels', 'freight_rules','extra1_goods_list','extra2_goods_list','store_login_url'));
- } else {
- // 编辑商品
- $form = json_decode(Yii::$app->request->post('form'), true);
- $form['mall_id'] = $this->mall_id;
- if ($form['extra']['platform_service_fee_setting']['service_fee_type'] == 1 && $form['extra']['service_fee_setting']['is_alone'] == 1 && $form['extra']['service_fee_setting'] && $form['extra']['platform_service_fee_setting']) {
- if ($form['extra']['service_fee_setting']['service_fee_ratio'] > $form['extra']['platform_service_fee_setting']['max_platform_ratio'] || $form['extra']['service_fee_setting']['service_fee_ratio'] < $form['extra']['platform_service_fee_setting']['min_platform_ratio']) {
- return $this->error('只能设置在平台服务费比例区间内的比例当前平台服务费比例:' . $form['extra']['platform_service_fee_setting']['min_platform_ratio'] . '%~' . $form['extra']['platform_service_fee_setting']['max_platform_ratio'] . '%');
- }
- }
- $res = StoreGoods::setData($form);
- if ($res === false) return $this->error(StoreGoods::getStaticError());
- return $this->success('操作成功');
- }
- }
- // 获取组件配置
- $addons_setting = AddonsLimit::getGlobalSetting($this->mall_id);
- $addons_arr = [AddonsEnum::ADDONS_NAME_DISTRIBUTION, AddonsEnum::ADDONS_NAME_AGENT, AddonsEnum::ADDONS_NAME_AREA, AddonsEnum::ADDONS_NAME_BOSS];
- if (!empty($addons_setting)) {
- foreach ($addons_setting as $key => $val) {
- if (!in_array($key, $addons_arr)) unset($addons_setting[$key]);
- }
- }
- // 公共调用
- $install_addons = GlobalInvoke::exec(GlobalInvoke::GOODS_DETAIL_EDIT, $this->mall_id, [
- 'type' => 'show_component',
- 'mall_id' => $this->mall_id,
- 'source' => StoreEnum::ADDONS_NAME,
- ]);
- foreach ($install_addons as $key => $val) {
- if(!is_array($val)){
- unset($install_addons[$key]);
- }
- $component = $val['component'] ?? '';
- if (!in_array($component, ['com-higo', 'com-devote'])) {
- unset($install_addons[$key]);
- }
- }
- return $this->render('/store-goods/edit', ['addons_settings' => $addons_setting,'components' => $install_addons]);
- }
- /**
- * 获取商品模式
- * @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);
- $addons_arr = [AddonsEnum::ADDONS_NAME_DISTRIBUTION, AddonsEnum::ADDONS_NAME_AGENT, AddonsEnum::ADDONS_NAME_AREA,AddonsEnum::ADDONS_NAME_DOUBLE_COPY,AddonsEnum::ADDONS_NAME_REBATE,AddonsEnum::ADDONS_NAME_BOSS];
- if (!empty($addons_setting)) {
- foreach ($addons_setting as $key => $val) {
- if (!in_array($key, $addons_arr)) unset($addons_setting[$key]);
- }
- }
- //门店存在的插件
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE_BOSS_AGENT)){
- $setting = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_STORE_BOSS_AGENT, 'basic');
- if (!empty($setting['is_enable'])){
- $addons_setting[AddonsEnum::ADDONS_NAME_STORE_BOSS_AGENT] = [
- 'components' => 'com-' . StringHelper::toUnderScore(AddonsEnum::ADDONS_NAME_STORE_BOSS_AGENT),
- 'class' => '',
- ];
- $addons_arr[] = AddonsEnum::ADDONS_NAME_STORE_BOSS_AGENT;
- }
- }
- 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 = StoreGoods::getOne([['id' => $params['id'], 'mall_id' => $this->mall_id]], true, ['attr']);
- $goods_model = StoreGoodsModel::getOne([['goods_id' => $params['id'], 'mall_id' => $this->mall_id]], true);
- $setting = [];
- if (!empty($goods_model['content'])) {
- $content = json_decode($goods_model['content'], true);
- foreach ($content as $key => $item) {
- if (in_array($key, $addons_arr)) {
- $setting[$key] = json_decode($item, true);
- }
- }
- }
- // 获取等级
- $level_params = ['where' => [['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'level,name'];
- $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);
- unset($commission_type_map['digital']);
- return $this->success('操作成功', compact('detail', 'level', 'setting', 'commission_type_map'));
- } else {
- $params = Yii::$app->request->post('form');
- $res = Yii::$app->services->validate->validate($params, [
- [['goods_id', 'store_id'], 'required'],
- [['goods_id', 'store_id'], 'integer'],
- [array_keys($addons_setting), 'string']
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // dd($params);
- try {
- $param = [
- 'mall_id' => $this->mall_id,
- 'store_id' => $params['store_id'],
- 'goods_id' => $params['goods_id'],
- 'content' => json_encode($params),
- ];
- $res = StoreGoodsModel::setData($param);
- if ($res === false) return $this->error(StoreGoodsModel::getStaticError());
- return $this->success("保存成功");
- } catch (\Exception $e) {
- return $this->error("保存失败,msg=" . $e->getMessage());
- }
- }
- }
- return $this->render('/store-goods/edit', ['addons_settings' => $addons_setting]);
- }
- /**
- * @name:
- * @msg: 商品审核操作
- * @param {*}
- * @return {*}
- */
- public function actionAudit()
- {
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $post = \Yii::$app->request->post();
- $rules = [
- [['goods_id', 'type'], 'required'],
- ['goods_id', 'integer'],
- ['type', 'in', 'range' => ['adopt', 'failed']],
- ['check_remark', 'required', 'when' => function ($model) {
- return $model->type == 'failed';
- }],
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $good = StoreGoods::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $post['goods_id']]);
- if (empty($good)) {
- return $this->error('商品不存在');
- }
- if ('adopt' == $post['type']) {
- $check_status = 1;
- } else {
- $check_status = 2;
- }
- $good->check_status = $check_status;
- $good->check_remark = $post['check_remark'];
- $good->updated_at = time();
- if (!$good->save()) {
- return $this->error('操作失败');
- }
- return $this->success('操作成功');
- }
- /**
- * @name:
- * @msg: 获取商品分类树形目录
- * @param {*}
- * @return {*}
- */
- public function actionTree()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $is_add = Yii::$app->request->get('is_add', 0);
- $store_id = Yii::$app->request->get('store_id', '');
- $cond = [['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]];
- if (!empty($store_id)) {
- $cond[] = ['store_id' => $store_id];
- }
- if($is_add) $cond[] = ['>', 'store_id', 0];
- $list = StoreGoodsCate::getCates($cond, [], true, 'id,name,parent_id');
- $list = StoreGoodsCate::getTreeCate($list);
- return $this->success('操作成功', compact('list'));
- }
- }
- }
- public function actionMutipleOff()
- {
- // if (!\Yii::$app->request->isPost) {
- // return $this->error('请求方式错误');
- // }
- // $good_ids = \Yii::$app->request->post('good_ids');
- // if (empty($good_ids) || !is_array($good_ids)) {
- // return $this->error('参数错误');
- // }
- //
- // if (empty($good_ids)) {
- // return $this->success('操作成功');
- // }
- //
- // $res = StoreGoods::updateAll(['is_on_sale' => 0, 'updated_at' => time(), 'check_status' => StoreEnum::CHECK_WAITING], ['mall_id' => $this->mall_id, 'id' => $good_ids]);
- // if (!$res) {
- // return $this->error('操作失败:' . StoreGoods::getStaticError());
- // }
- // return $this->success('操作成功');
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $good_ids = \Yii::$app->request->post('good_ids');
- $type = \Yii::$app->request->post('type');
- $where = [];
- // 是否需要审核
- $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
- $goods_auth = $basic['goods_auth'] ?? 0;
- $check_status = !$goods_auth ? StoreEnum::CHECK_ADOPT : StoreEnum::CHECK_WAITING;
- if ($type == 1) {
- $where = ['is_on_sale' => 0, 'updated_at' => time(), 'check_status' => $check_status];
- } else if ($type == 2) {
- $where = ['is_on_sale' => 1, 'updated_at' => time(), 'check_status' => $check_status];
- } else if ($type == 3) {
- $where = ['status' => StatusEnum::DELETE, 'updated_at' => time(), 'check_status' => $check_status];
- }
- if (empty($good_ids) || !is_array($good_ids) || !$type) {
- return $this->error('参数错误');
- }
- if (empty($good_ids)) {
- return $this->success('操作成功');
- }
- $res = StoreGoods::updateAll($where, ['mall_id' => $this->mall_id, 'id' => $good_ids]);
- if (!$res) {
- return $this->error('操作失败:' . StoreGoods::getStaticError());
- }
- return $this->success('操作成功');
- }
- public function actionSearch()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $rules = [
- [['keyword'], 'string']
- ];
- $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'], 'is_on_sale' => 1,'check_status'=>1, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]];
- isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]];
- $sort = !empty($sort) ? $sort . ',sort ASC,id DESC' : 'sort ASC,id DESC';
- $params = array('where' => $where, 'limit' => 15, 'order' => $sort, 'group' => 'id');
- $page_data = StoreGoods::listPage($params, false, true);
- if ($page_data === false)
- return $this->error(Goods::getStaticError());
- return $this->success('操作成功', $page_data);
- }
- }
- return $this->render($this->action->id);
- }
- public function actionSearchWithStore()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $rules = [
- [['keyword'], 'string']
- ];
- $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'], 'is_on_sale' => 1,'check_status'=>1, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]];
- isset($get['keyword']) && $where[] = ['or', ['like', 'goods_name', $get['keyword']], ['=', 'id', $get['keyword']]];
- $sort = !empty($sort) ? $sort . ',sort ASC,id DESC' : 'sort ASC,id DESC';
- $params = array('where' => $where, 'limit' => 15, 'order' => $sort, 'group' => 'id');
- $page_data = StoreGoods::listPage($params, false, true);
- if ($page_data === false)
- return $this->error(Goods::getStaticError());
- if(!empty($page_data['list'])){
- $store_ids = array_column($page_data['list'],'store_id');
- $store_list = Store::find()->where(['id'=>$store_ids])->indexBy('id')->asArray()->all();
- foreach($page_data['list'] as &$item){
- $item['store_name'] = '';
- if(!empty($store_list[$item['store_id']])){
- $item['store_name'] = $store_list[$item['store_id']]['store_name'];
- }
- }
- }
- return $this->success('操作成功', $page_data);
- }
- }
- return $this->render($this->action->id);
- }
- }
|