1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /*
- * 店铺规格值
- * 每个店铺都有对应分类下保存的规格值
- */
- namespace app\api\controller;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Sellerspec extends MobileSeller
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerspec.lang.php');
- }
- /**
- * @api {POST} api/Sellerspec/save_spec 保存规格值
- * @apiVersion 1.0.0
- * @apiGroup Sellerspec
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {Int} gc_id 商品分类ID
- * @apiParam {Object} spec_list 规格列表
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function save_spec()
- {
- $spec_list = input('post.spec_list/a');
- $gc_id = intval(input('post.gc_id'));
- if (empty($spec_list) || $gc_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $spec_model = model('spec');
- foreach ($spec_list as $sp_id => $spec) {
- $spvalue_ids = array();
- $specvalue_list = array();
- foreach ($spec['value'] as $val) {
- $val['spvalue_name'] = trim($val['spvalue_name']);
- if (!empty($val['spvalue_name'])) {
- if (isset($val['spvalue_id'])) {
- $spvalue_ids[] = $val['spvalue_id'];
- $condition = array();
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $condition[] = array('spvalue_id', '=', $val['spvalue_id']);
- $update = array(
- 'spvalue_name' => $val['spvalue_name'],
- );
- $spec_model->editSpecvalue($update, $condition);
- } else {
- $specvalue_list[] = array(
- 'spvalue_name' => $val['spvalue_name'],
- 'sp_id' => $sp_id,
- 'gc_id' => $gc_id,
- 'store_id' => $this->store_info['store_id'],
- 'spvalue_color' => '',
- 'spvalue_sort' => 255
- );
- }
- }
- }
- $condition = array();
- $condition[] = array('store_id', '=', $this->store_info['store_id']);
- $condition[] = array('sp_id', '=', $sp_id);
- if (!empty($spvalue_ids)) {
- $condition[] = array('spvalue_id', 'not in', $spvalue_ids);
- }
- $spec_model->delSpecvalue($condition);
- if (!empty($specvalue_list)) {
- $spec_model->addSpecvalueALL($specvalue_list);
- }
- }
- ds_json_encode(10000, lang('ds_common_op_succ'));
- }
- }
|