checkToken(); if ($token['code'] < 0) { echo $this->response($token); exit; } } /** * 添加商品 * @return mixed */ public function addGoods() { $category_id = input("category_id", 0);// 分类id $category_json = json_encode($category_id);//分类字符串 $category_id = ''; $data = [ 'goods_name' => input("goods_name", ""),// 商品名称, 'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id, 'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称, 'is_limit' => input("is_limit", "0"),// 商品是否限购, 'limit_type' => input("limit_type", "1"),// 商品限购类型, 'site_id' => $this->site_id, 'category_id' => $category_id, 'category_json' => $category_json, 'goods_image' => input("goods_image", ""),// 商品主图路径 'goods_content' => input("goods_content", ""),// 商品详情 'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架) 'price' => input("price", 0),// 商品价格(取第一个sku) 'renew_price' => input("renew_price", 0), // 续费价格 'market_price' => input("market_price", 0),// 市场价格(取第一个sku) 'cost_price' => input("cost_price", 0),// 成本价(取第一个sku) 'sku_no' => input("sku_no", ""),// 商品sku编码 'weight' => input("weight", ""),// 重量 'volume' => input("volume", ""),// 体积 'goods_stock' => input("goods_stock", 0),// 商品库存(总和) 'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警 'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式 'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式 'introduction' => input("introduction", ""),// 促销语 'keywords' => input("keywords", ""),// 关键词 'unit' => input("unit", ""),// 单位 'sort' => input("sort", 0),// 排序, 'video_url' => input("video_url", ""),// 视频 'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据 'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合 'label_id' => input("label_id", ''),// 商品分组id 'brand_id' => input("brand_id", 0),//品牌id 'virtual_sale' => input("virtual_sale", 0),// 虚拟销量 'max_buy' => input("max_buy", 0),// 限购 'min_buy' => input("min_buy", 0),// 起售 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐 'timer_on' => strtotime(input('timer_on', 0)),//定时上架 'timer_off' => strtotime(input('timer_off', 0)),//定时下架 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣 'qr_id' => input('qr_id', 0),// 社群二维码id 'template_id' => input('template_id', 0), // 商品海报id 'sale_show' => input('sale_show', 0),// 'stock_show' => input('stock_show', 0),// 'market_price_show' => input('market_price_show', 0),// 'barrage_show' => input('barrage_show', 0),// 'form_id' => input('form_id', 0), 'sale_channel' => input('sale_channel', 'all'), 'sale_store' => input('sale_store', 'all'), 'card_type' => input('card_type', ''), 'validity_type' => input('validity_type', 0), 'discount_goods_type' => input('discount_goods_type', 'all'), 'discount' => input('discount', 0), 'common_num' => input('common_num', 0), 'relation_goods' => input('relation_goods', '[]'), 'is_unify_pirce' => input('is_unify_pirce', 1), 'is_cloud_zmxx' => input('is_cloud_zmxx', 0), 'discount_type' => input('discount_type', 1), 'cloud_card_type' => input('cloud_card_type', 'discount_week'), 'downPaymentPeriods' => input('downPaymentPeriods', 0), 'downPayment' => input('downPayment', 0), 'perPeriodPriceArray' => input('perPeriodPriceArray'), 'periods' => input('periods',0), 'card_template_id' => input('card_template_id', ''), 'change_type' => input('change_type', ''), 'least_period' => input('periods', ''), 'is_alipay_public' => input('is_alipay_public', 0), 'use_rule' => input('use_rule'), 'is_zmxx' => 0, 'alipay_cat_id' =>'', ]; $common_num= $data['periods']?:$data['common_num']; if ($data['is_cloud_zmxx'] && $data['card_type'] != 'commoncard') return $this->response(error(-1, '芝麻先享仅支持通用卡')); if ($data['is_cloud_zmxx'] && !$data['use_rule']) return $this->response(error(-1, '使用规则不能为空')); if ($data['is_cloud_zmxx']) { $data['is_zmxx'] = 1; $num_price = $data['price'] / $common_num;//平均价格 $market_price = $data['market_price'] / $common_num; $data['average_original_price'] = $market_price; $data['average_discount_price'] = $num_price; if ($data['discount_type'] == 1) { if ($num_price < $data['downPayment']) return $this->response(error(-1, '前期优惠价格必须小于平均优惠价格')); } else { $downPaymentPeriods = str_replace(',', ',', $data['downPaymentPeriods']); $PaymentPeriods = explode(',', $downPaymentPeriods); if (count($PaymentPeriods) >= $common_num) return $this->response(error(-1, '后期优惠次数不能大于总次数')); $current = current($PaymentPeriods); while ($next = next($PaymentPeriods)) { if ($next > $current) { return $this->response(error(-1, '后期优惠价格必须小于或者等与前一期价格')); } $current = $next; } } } if ($data['validity_type'] == 1) { $data['validity_day'] = input("validity_day", 0); } elseif ($data['validity_type'] == 2) { $data['validity_time'] = strtotime(input("validity_time", '')); } $virtual_goods_model = new CardGoods(); $res = $virtual_goods_model->addGoods($data); return $this->response($res); } /** * 编辑商品 * @return mixed */ public function editGoods() { $virtual_goods_model = new CardGoods(); $category_id = input("category_id", 0);// 分类id $category_json = json_encode($category_id);//分类字符串 $category_id = ''; $data = [ 'goods_id' => input("goods_id", 0),// 商品id 'goods_name' => input("goods_name", ""),// 商品名称, 'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id, 'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称, 'is_limit' => input("is_limit", "0"),// 商品是否限购, 'limit_type' => input("limit_type", "1"),// 商品限购类型, 'site_id' => $this->site_id, 'category_id' => $category_id, 'category_json' => $category_json, 'goods_image' => input("goods_image", ""),// 商品主图路径 'goods_content' => input("goods_content", ""),// 商品详情 'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架) 'price' => input("price", 0),// 商品价格(取第一个sku) 'renew_price' => input("renew_price", 0), // 续费价格 'market_price' => input("market_price", 0),// 市场价格(取第一个sku) 'cost_price' => input("cost_price", 0),// 成本价(取第一个sku) 'sku_no' => input("sku_no", ""),// 商品sku编码 'weight' => input("weight", ""),// 重量 'volume' => input("volume", ""),// 体积 'goods_stock' => input("goods_stock", 0),// 商品库存(总和) 'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警 'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式 'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式 'introduction' => input("introduction", ""),// 促销语 'keywords' => input("keywords", ""),// 关键词 'unit' => input("unit", ""),// 单位 'sort' => input("sort", 0),// 排序, 'video_url' => input("video_url", ""),// 视频 'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据 'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合 'label_id' => input("label_id", ''),// 商品分组id 'brand_id' => input("brand_id", 0),//品牌id 'virtual_sale' => input("virtual_sale", 0),// 虚拟销量 'max_buy' => input("max_buy", 0),// 限购 'min_buy' => input("min_buy", 0),// 起售 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐 'timer_on' => strtotime(input('timer_on', 0)),//定时上架 'timer_off' => strtotime(input('timer_off', 0)),//定时下架 'spec_type_status' => input('spec_type_status', 0), 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣 'qr_id' => input('qr_id', 0),// 社群二维码id 'template_id' => input('template_id', 0), // 商品海报id 'sale_show' => input('sale_show', 0),// 'stock_show' => input('stock_show', 0),// 'market_price_show' => input('market_price_show', 0),// 'barrage_show' => input('barrage_show', 0),// 'form_id' => input('form_id', 0), 'sale_channel' => input('sale_channel', 'all'), 'sale_store' => input('sale_store', 'all'), 'validity_type' => input('validity_type', 0), 'discount_goods_type' => input('discount_goods_type', 'all'), 'discount' => input('discount', 0), 'common_num' => input('common_num', 0), 'relation_goods' => input('relation_goods', '[]'), 'is_unify_pirce' => input('is_unify_pirce', 1), 'discount_type' => input('discount_type', ''), 'downPaymentPeriods' => input('downPaymentPeriods', 0), 'downPayment' => input('downPayment', 0), 'perPeriodPriceArray' => input('perPeriodPriceArray'), 'periods' => input('periods'), 'card_template_id' => input('card_template_id', ''), 'change_type' => input('change_type', ''), 'least_period' => input('periods', ''), 'is_alipay_public' => input('is_alipay_public', 0), 'use_rule' => input('use_rule'), ]; $num_price = $data['price'] / $data['common_num']; if ($data['discount_type'] == 1) { if ($num_price < $data['downPayment']) return $this->response(error(-1, '前期优惠价格必须小于平均优惠价格')); } else if ($data['discount_type'] == 2) { $downPaymentPeriods = str_replace(',', ',', $data['downPaymentPeriods']); $PaymentPeriods = explode(',', $downPaymentPeriods); if (count($PaymentPeriods) >= $data['common_num']) return $this->response(error(-1, '后期优惠次数不能大于总次数')); $current = current($PaymentPeriods); while ($next = next($PaymentPeriods)) { if ($next > $current) { return $this->response(error(-1, '后期优惠价格必须小于或者等与前一期价格')); } $current = $next; } } $market_price = $data['market_price'] / $data['common_num']; $data['renew_price'] = $data['price']; $data['average_original_price'] = $market_price; $data['average_discount_price'] = $num_price; if ($data['validity_type'] == 1) { $data['validity_day'] = input("validity_day", 0); } elseif ($data['validity_type'] == 2) { $data['validity_time'] = strtotime(input("validity_time", '')); } $data['periods'] = $data['common_num'];//临时解决客商家端发布产品 $res = $virtual_goods_model->editGoods($data); return $this->response($res); } public function getCardType() { $virtual_goods_model = new CardGoods(); return $this->response($this->success($virtual_goods_model->getCardType())); } public function getServiceList() { $goods_service_model = new GoodsServiceModel(); $service_list = $goods_service_model->getServiceList([['site_id', '=', $this->site_id]], 'id,service_name,icon'); return $this->response($service_list); } public function editGetGoodsInfo() { $virtual_goods_model = new CardGoods(); $goods_model = new GoodsModel(); $goods_id = input("goods_id", 0); $goods_info = $virtual_goods_model->editGetGoodsInfo(['goods_id' => $goods_id, 'site_id' => $this->site_id]); if (empty($goods_info['data'])) $this->error('未获取到商品信息'); $goods_sku_list = $goods_model->getGoodsSkuList([['goods_id', '=', $goods_id], ['site_id', '=', $this->site_id]], "sku_id,sku_name,sku_no,sku_spec_format,price,market_price,cost_price,stock,virtual_indate,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default", '')['data']; $goods_info['data']['goods_sku_data'] = $goods_sku_list; $store_is_exit = addon_is_exit('store', $this->site_id); if ($store_is_exit && $goods_info['data']['sale_store'] != 'all') { $store_list = (new StoreModel())->getStoreList([['site_id', '=', $this->site_id], ['store_id', 'in', $goods_info['data']['sale_store']]], 'store_id,store_name,status,address,full_address,is_frozen'); $goods_info['data']['store_list'] = $store_list['data']; } return $this->response($goods_info); } /** * 选择门店 * @return mixed */ public function storeList() { $store_list = (new StoreModel())->getStoreList([['site_id', '=', $this->site_id]], 'store_id,store_name,status,address,full_address,is_frozen'); return $this->response($store_list); } /*** * 获取默认商品信息 * @return false|string */ public function defGoodsTemplate() { $config = new Config(); $data = $config->getTemplate($this->agent_id)['data']['value']; return $this->response($data); } }