Sellergoods.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 卖家商品控制器
  15. */
  16. class Sellergoods extends MobileSeller {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergoodsadd.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Sellergoods/goods_list 出售中的商品列表
  23. * @apiVersion 1.0.0
  24. * @apiGroup Sellergoods
  25. *
  26. * @apiHeader {String} X-DS-KEY 卖家授权token
  27. *
  28. * @apiParam {String} keyword 关键词
  29. * @apiParam {String} goods_type 商品类型 lockup违规的商品 offline仓库的商品 waitverify等待审核的商品
  30. * @apiParam {Int} search_type 0商品名 1货号 2商品公共ID
  31. * @apiParam {String} page 页码
  32. * @apiParam {String} pagesize 每页显示数量
  33. *
  34. * @apiSuccess {String} code 返回码,10000为成功
  35. * @apiSuccess {String} message 返回消息
  36. * @apiSuccess {Object} result 返回数据
  37. * @apiSuccess {Object[]} result.goods_list 商品列表
  38. * @apiSuccess {String} result.goods_list.goods_addtime 添加时间
  39. * @apiSuccess {String} result.goods_list.goods_commonid 商品公共ID
  40. * @apiSuccess {String} result.goods_list.goods_image 商品图片
  41. * @apiSuccess {String} result.goods_list.goods_lock 商品锁定 0未锁,1已锁
  42. * @apiSuccess {String} result.goods_list.goods_name 商品名称
  43. * @apiSuccess {String} result.goods_list.goods_price 商品价格
  44. * @apiSuccess {String} result.goods_list.goods_state 商品状态 0:下架 1:正常 10:违规(禁售)
  45. * @apiSuccess {String} result.goods_list.goods_storage_sum 商品库存
  46. * @apiSuccess {Int} result.page_total 总页数
  47. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  48. */
  49. public function goods_list() {
  50. $keyword = input('post.keyword');
  51. $goods_type = input('post.goods_type');
  52. $search_type = input('post.search_type');
  53. $goods_model = model('goods');
  54. $condition = array();
  55. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  56. if (trim($keyword) != '') {
  57. switch ($search_type) {
  58. case 0:
  59. $condition[] = array('goods_name', 'like', '%' . trim($keyword) . '%');
  60. break;
  61. case 1:
  62. $condition[] = array('goods_serial', 'like', '%' . trim($keyword) . '%');
  63. break;
  64. case 2:
  65. $condition[] = array('goods_commonid', '=', intval($keyword));
  66. break;
  67. }
  68. }
  69. $fields = 'gc_id,goods_commonid,goods_name,goods_price,goods_addtime,goods_image,goods_state,goods_lock';
  70. switch ($goods_type) {
  71. // 违规的商品
  72. case 'lockup':
  73. $goods_list = $goods_model->getGoodsCommonLockUpList($condition, $fields, $this->pagesize);
  74. break;
  75. //仓库的商品
  76. case 'offline':
  77. $goods_list = $goods_model->getGoodsCommonOfflineList($condition, $fields, $this->pagesize);
  78. break;
  79. //等待审核的商品
  80. case 'waitverify':
  81. $goods_list = $goods_model->getGoodsCommonWaitVerifyList($condition);
  82. break;
  83. default:
  84. $goods_list = $goods_model->getGoodsCommonOnlineList($condition, $fields, $this->pagesize);
  85. break;
  86. }
  87. // 计算库存
  88. $storage_array = $goods_model->calculateStorage($goods_list);
  89. // 整理输出的数据格式
  90. foreach ($goods_list as $key => $value) {
  91. $goods_list[$key]['goods_storage_sum'] = $storage_array[$value['goods_commonid']]['sum'];
  92. $goods_list[$key]['goods_addtime'] = date('Y-m-d', $goods_list[$key]['goods_addtime']);
  93. $goods_list[$key]['goods_image'] = goods_cthumb($goods_list[$key]['goods_image']);
  94. }
  95. $result = array_merge(array('goods_list' => $goods_list), mobile_page($goods_model->page_info));
  96. ds_json_encode(10000, '', $result);
  97. }
  98. /**
  99. * @api {POST} api/Sellergoods/goods_show 商品上架
  100. * @apiVersion 1.0.0
  101. * @apiGroup Sellergoods
  102. *
  103. * @apiHeader {String} X-DS-KEY 卖家授权token
  104. *
  105. * @apiParam {Int} commonid 商品公共ID
  106. *
  107. * @apiSuccess {String} code 返回码,10000为成功
  108. * @apiSuccess {String} message 返回消息
  109. * @apiSuccess {Object} result 返回数据
  110. */
  111. public function goods_show() {
  112. if ($this->store_info['store_state'] != 1) {
  113. ds_json_encode(10001, lang('wait_administrator_review_goods'));
  114. }
  115. $commonid = input('param.commonid');
  116. if (!preg_match('/^[\d,]+$/i', $commonid)) {
  117. ds_json_encode(10001, lang('para_error'));
  118. }
  119. $commonid_array = explode(',', $commonid);
  120. if ($this->store_info['store_state'] != 1) {
  121. ds_json_encode(10001, lang('store_goods_index_goods_show_fail'));
  122. }
  123. $return = model('goods')->editProducesOnline(array(array('goods_commonid', 'in', $commonid_array), array('store_id', '=', $this->store_info['store_id'])));
  124. if ($return) {
  125. // 添加操作日志
  126. $this->recordSellerlog('商品上架,平台货号:' . $commonid);
  127. ds_json_encode(10000, '', 1);
  128. } else {
  129. ds_json_encode(10001, lang('store_goods_index_goods_show_fail'));
  130. }
  131. }
  132. /**
  133. * @api {POST} api/Sellergoods/goods_unshow 商品下架
  134. * @apiVersion 1.0.0
  135. * @apiGroup Sellergoods
  136. *
  137. * @apiHeader {String} X-DS-KEY 卖家授权token
  138. *
  139. * @apiParam {Int} commonid 商品公共ID
  140. *
  141. * @apiSuccess {String} code 返回码,10000为成功
  142. * @apiSuccess {String} message 返回消息
  143. * @apiSuccess {Object} result 返回数据
  144. */
  145. public function goods_unshow() {
  146. //参考PC端代码
  147. $common_id = $this->checkRequestCommonId(input('param.commonid'));
  148. $commonid_array = explode(',', $common_id);
  149. $goods_model = model('goods');
  150. $where = array();
  151. $where[] = array('goods_commonid', 'in', $commonid_array);
  152. $where[] = array('store_id', '=', $this->store_info['store_id']);
  153. $return = model('goods')->editProducesOffline($where);
  154. if ($return) {
  155. // 更新优惠套餐状态关闭
  156. $goods_list = $goods_model->getGoodsList($where, 'goods_id');
  157. if (!empty($goods_list)) {
  158. $goodsid_array = array();
  159. foreach ($goods_list as $val) {
  160. $goodsid_array[] = $val['goods_id'];
  161. }
  162. model('pbundling')->editBundlingCloseByGoodsIds(array(array('goods_id', 'in', $goodsid_array)));
  163. }
  164. // 添加操作日志
  165. $this->recordSellerlog('商品下架,平台货号:' . $common_id);
  166. ds_json_encode(10000, '', 1);
  167. } else {
  168. ds_json_encode(10001, lang('store_goods_index_goods_unshow_fail'));
  169. }
  170. }
  171. /**
  172. * 验证commonid
  173. */
  174. private function checkRequestCommonId($common_ids) {
  175. if (!preg_match('/^[\d,]+$/i', $common_ids)) {
  176. ds_json_encode(10001, lang('para_error'));
  177. }
  178. return $common_ids;
  179. }
  180. /**
  181. * @api {POST} api/Sellergoods/goods_unshow 商品删除
  182. * @apiVersion 1.0.0
  183. * @apiGroup Sellergoods
  184. *
  185. * @apiHeader {String} X-DS-KEY 卖家授权token
  186. *
  187. * @apiParam {Int} commonid 商品公共ID
  188. *
  189. * @apiSuccess {String} code 返回码,10000为成功
  190. * @apiSuccess {String} message 返回消息
  191. * @apiSuccess {Object} result 返回数据
  192. */
  193. public function drop_goods() {
  194. $commonid = input('param.commonid');
  195. $common_id = $this->checkRequestCommonId($commonid);
  196. $commonid_array = explode(',', $common_id);
  197. $goods_model = model('goods');
  198. $where = array();
  199. $where[] = array('goods_commonid', 'in', $commonid_array);
  200. $where[] = array('store_id', '=', $this->store_info['store_id']);
  201. $return = $goods_model->delGoodsNoLock($where);
  202. if ($return) {
  203. // 添加操作日志
  204. $this->recordSellerlog('删除商品,平台货号:' . $common_id);
  205. ds_json_encode(10000, '', 1);
  206. } else {
  207. ds_json_encode(10001, lang('store_goods_index_goods_del_fail'));
  208. }
  209. }
  210. /**
  211. * @api {POST} api/Sellergoods/get_common_data 获取新增/编辑商品的公共数据
  212. * @apiVersion 1.0.0
  213. * @apiGroup Sellergoods
  214. *
  215. * @apiHeader {String} X-DS-KEY 卖家授权token
  216. *
  217. * @apiParam {Int} class_id 商品分类ID
  218. *
  219. * @apiSuccess {String} code 返回码,10000为成功
  220. * @apiSuccess {String} message 返回消息
  221. * @apiSuccess {Object} result 返回数据
  222. * @apiSuccess {Object} result.attr_list 属性列表,键为属性名id
  223. * @apiSuccess {String} result.attr_list.attr_name 属性名
  224. * @apiSuccess {Object[]} result.attr_list.value 属性值列表
  225. * @apiSuccess {Int} result.attr_list.value.attrvalue_id 属性值id
  226. * @apiSuccess {String} result.attr_list.value.attrvalue_name 属性值名称
  227. * @apiSuccess {Object[]} result.brand_list 品牌列表(返回字段参考brand表)
  228. * @apiSuccess {Object} result.goods_class 商品分类
  229. * @apiSuccess {Int} result.goods_class.gc_id 商品分类ID
  230. * @apiSuccess {Int} result.goods_class.gc_id_1 一级商品分类ID
  231. * @apiSuccess {Int} result.goods_class.gc_id_2 二级商品分类ID
  232. * @apiSuccess {Int} result.goods_class.gc_id_3 三级商品分类ID
  233. * @apiSuccess {Int} result.goods_class.gc_virtual 是否允许发布虚拟商品(0否1是)
  234. * @apiSuccess {String} result.goods_class.gctag_name 商品分类名称
  235. * @apiSuccess {String} result.goods_class.gctag_value 商品分类标签
  236. * @apiSuccess {Int} result.goods_class.type_id 类型ID
  237. * @apiSuccess {Object} result.sign_i 规格数量
  238. * @apiSuccess {Object} result.spec_json 规格值列表(键为规格名id,值中的键为规格值id)
  239. * @apiSuccess {String} result.spec_json.spvalue_color 规格值颜色
  240. * @apiSuccess {String} result.spec_json.spvalue_name 规格值
  241. * @apiSuccess {Object} result.spec_list 按规格名分类的规格列表(键为规格名id)
  242. * @apiSuccess {String} result.spec_list.sp_name 规格名
  243. * @apiSuccess {Object[]} result.spec_list.value 规格值列表
  244. * @apiSuccess {String} result.spec_list.value .spvalue_color 规格值颜色
  245. * @apiSuccess {String} result.spec_list.value .spvalue_name 规格值
  246. * @apiSuccess {Int} result.spec_list.value .spvalue_name 规格值id
  247. */
  248. public function get_common_data() {
  249. $result = array();
  250. $class_id = intval(input('param.class_id'));
  251. $goods_class = model('goodsclass')->getGoodsclassLineForTag($class_id);
  252. $result['goods_class'] = $goods_class;
  253. $type_model = model('type');
  254. // 获取类型相关数据
  255. $typeinfo = $type_model->getAttribute($goods_class['type_id'], $this->store_info['store_id'], $class_id);
  256. list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
  257. $result['spec_json'] = $spec_json;
  258. $result['sign_i'] = count($spec_list);
  259. $result['spec_list'] = $spec_list;
  260. $result['attr_list'] = $attr_list;
  261. $result['brand_list'] = $brand_list;
  262. ds_json_encode(10000, '', $result);
  263. }
  264. /**
  265. * @api {POST} api/Sellergoods/edit_goods 获取商品信息
  266. * @apiVersion 1.0.0
  267. * @apiGroup Sellergoods
  268. *
  269. * @apiHeader {String} X-DS-KEY 卖家授权token
  270. *
  271. * @apiParam {Int} class_id 商品分类ID
  272. *
  273. * @apiSuccess {String} code 返回码,10000为成功
  274. * @apiSuccess {String} message 返回消息
  275. * @apiSuccess {Object} result 返回数据
  276. * @apiSuccess {Object} result.area 商品地区信息(返回字段参考area表)
  277. * @apiSuccess {Int[]} result.attr_checked 选择的属性值id
  278. * @apiSuccess {Object} result.goods 商品信息(返回字段参考goodscommon表)
  279. * @apiSuccess {Int} result.goods.goods_storage 商品总库存
  280. * @apiSuccess {Object[]} result.goods.mb_body 商品详情
  281. * @apiSuccess {String} result.goods.mb_body.type 商品详情类型(image图片text文字)
  282. * @apiSuccess {String} result.goods.mb_body.value 商品详情值
  283. * @apiSuccess {String} result.goods.mb_body.value_url 商品详情图片链接
  284. * @apiSuccess {String} result.goods.goods_image_url 商品图片
  285. * @apiSuccess {Object} result.sp_value 规格值列表(键为规格值id升序排列的字符串)
  286. * @apiSuccess {Int} result.sp_value.alarm 库存预警值
  287. * @apiSuccess {Int} result.sp_value.color 颜色规格id
  288. * @apiSuccess {Int} result.sp_value.id 商品id
  289. * @apiSuccess {String} result.sp_value.label 规格名(用|分隔)
  290. * @apiSuccess {Float} result.sp_value.marketprice 市场价
  291. * @apiSuccess {Float} result.sp_value.price 价格
  292. * @apiSuccess {String} result.sp_value.sku 货号
  293. * @apiSuccess {Object} result.sp_value.sp_value 规格值列表(键为规格值id,值为规格值名称)
  294. * @apiSuccess {Int} result.sp_value.stock 库存
  295. */
  296. public function edit_goods() {
  297. $common_id = intval(input('param.commonid'));
  298. if ($common_id <= 0) {
  299. ds_json_encode(10001, lang('param_error'));
  300. }
  301. $goods_model = model('goods');
  302. $goodscommon_info = $goods_model->getGoodsCommonInfoByID($common_id);
  303. if (empty($goodscommon_info) || $goodscommon_info['store_id'] != $this->store_info['store_id'] || $goodscommon_info['goods_lock'] == 1) {
  304. ds_json_encode(10001, lang('goods_not_exist_or_lock'));
  305. }
  306. $result = array();
  307. $where = array('goods_commonid' => $common_id, 'store_id' => $this->store_info['store_id']);
  308. $goodscommon_info['goods_storage'] = $goods_model->getGoodsSum($where, 'goods_storage');
  309. $goodscommon_info['spec_name'] = unserialize($goodscommon_info['spec_name']);
  310. if ($goodscommon_info['mobile_body'] != '') {
  311. $goodscommon_info['mb_body'] = unserialize($goodscommon_info['mobile_body']);
  312. if (is_array($goodscommon_info['mb_body'])) {
  313. $mobile_body = '[';
  314. foreach ($goodscommon_info['mb_body'] as $val) {
  315. $mobile_body .= '{"type":"' . $val['type'] . '","value":"' . $val['value'] . '"},';
  316. }
  317. $mobile_body = rtrim($mobile_body, ',') . ']';
  318. }
  319. $goodscommon_info['mobile_body'] = $mobile_body;
  320. }
  321. $goodscommon_info['goods_image_url'] = goods_thumb($goodscommon_info, 240);
  322. $area = model('area')->getAreaInfo(array('area_id' => $goodscommon_info['areaid_2'] ? $goodscommon_info['areaid_2'] : $goodscommon_info['areaid_1']));
  323. $result['area'] = $area;
  324. $type_model = model('type');
  325. // 取得商品规格的输入值
  326. $goods_array = $goods_model->getGoodsList($where, 'goods_id,goods_marketprice,goods_price,goods_weight,goods_storage,goods_serial,goods_storage_alarm,goods_spec,color_id,virtual_content');
  327. $sp_value = array();
  328. if (is_array($goods_array) && !empty($goods_array)) {
  329. $goodscommon_info['goods_weight'] = $goods_array[0]['goods_weight'];
  330. switch($goodscommon_info['virtual_type']){
  331. case 1:
  332. $goodscommon_info['virtual_type_text']='卡券商品';
  333. $goodscommon_info['vc_card'] = $goods_array[0]['virtual_content'];
  334. if($goodscommon_info['vc_card']){
  335. $card_list=explode("\r\n",$goodscommon_info['vc_card']);
  336. $goodscommon_info['card_num'] = count($card_list);
  337. }
  338. break;
  339. case 2:
  340. $goodscommon_info['virtual_type_text']='网盘商品';
  341. $goodscommon_info['vc_pan'] = $goods_array[0]['virtual_content'];
  342. break;
  343. case 3:
  344. $goodscommon_info['virtual_type_text']='下载商品';
  345. $goodscommon_info['vc_file'] = $goods_array[0]['virtual_content'];
  346. break;
  347. default:
  348. $goodscommon_info['virtual_type_text']='核销商品';
  349. }
  350. // 取得已选择了哪些商品的属性
  351. $attr_checked_l = $type_model->typeRelatedList('goodsattrindex', array(
  352. 'goods_id' => intval($goods_array[0]['goods_id'])
  353. ), 'attrvalue_id');
  354. $attr_checked = array();
  355. if (is_array($attr_checked_l) && !empty($attr_checked_l)) {
  356. foreach ($attr_checked_l as $val) {
  357. $attr_checked [] = $val ['attrvalue_id'];
  358. }
  359. }
  360. $result['attr_checked'] = $attr_checked;
  361. $spec_checked = array();
  362. foreach ($goods_array as $k => $v) {
  363. $a = unserialize($v['goods_spec']);
  364. if (!empty($a)) {
  365. foreach ($a as $key => $val) {
  366. $spec_checked[$key]['id'] = $key;
  367. $spec_checked[$key]['name'] = addslashes($val);
  368. }
  369. $matchs = array_keys($a);
  370. sort($matchs);
  371. $id = str_replace(',', '', implode(',', $matchs));
  372. $sp_value[$id] = array(
  373. 'sp_value' => $a,
  374. 'label' => implode('|', array_values($a)),
  375. 'color' => $v['color_id'],
  376. 'marketprice' => $v['goods_marketprice'],
  377. 'price' => $v['goods_price'],
  378. 'id' => $v['goods_id'],
  379. 'goods_weight' => $v['goods_weight'],
  380. 'stock' => $v['goods_storage'],
  381. 'alarm' => $v['goods_storage_alarm'],
  382. 'sku' => $v['goods_serial'],
  383. );
  384. switch($goodscommon_info['virtual_type']){
  385. case 1:
  386. $sp_value[$id]['vc_card'] = $v['virtual_content'];
  387. if($sp_value[$id]['vc_card']){
  388. $card_list=explode("\r\n",$sp_value[$id]['vc_card']);
  389. $sp_value[$id]['vc_card']['card_num'] = count($card_list);
  390. }
  391. break;
  392. case 2:
  393. $sp_value[$id]['vc_pan'] = $v['virtual_content'];
  394. break;
  395. case 3:
  396. $sp_value[$id]['vc_file'] = $v['virtual_content'];
  397. break;
  398. }
  399. }
  400. }
  401. $result['spec_checked'] = $spec_checked;
  402. }
  403. $goodscommon_info['goodsvideo_url'] = goods_video($goodscommon_info['goodsvideo_name']);
  404. $result['goods'] = $goodscommon_info;
  405. $result['sp_value'] = $sp_value;
  406. // 实例化店铺商品分类模型
  407. $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => $this->store_info['store_id'], 'storegc_state' => '1'));
  408. //处理商品所属分类
  409. $store_goods_class_tmp = array();
  410. if (!empty($store_goods_class)) {
  411. foreach ($store_goods_class as $k => $v) {
  412. $store_goods_class_tmp[$v['storegc_id']] = $v;
  413. if (isset($v['child'])) {
  414. foreach ($v['child'] as $son_k => $son_v) {
  415. $store_goods_class_tmp[$son_v['storegc_id']] = $son_v;
  416. }
  417. }
  418. }
  419. }
  420. $result['store_goods_class'] = $store_goods_class_tmp;
  421. $goodscommon_info['goods_stcids'] = trim($goodscommon_info['goods_stcids'], ',');
  422. $goods_stcids = empty($goodscommon_info['goods_stcids']) ? array() : explode(',', $goodscommon_info['goods_stcids']);
  423. $goods_stcids_tmp = $goods_stcids_new = array();
  424. if (!empty($goods_stcids)) {
  425. foreach ($goods_stcids as $k => $v) {
  426. if (isset($store_goods_class_tmp[$v])) {
  427. $storegc_parent_id = $store_goods_class_tmp[$v]['storegc_parent_id'];
  428. } else {
  429. $storegc_parent_id = 0;
  430. }
  431. //分类进行分组,构造为array('1'=>array(5,6,8));
  432. if ($storegc_parent_id > 0) {//如果为二级分类,则分组到父级分类下
  433. $goods_stcids_tmp[$storegc_parent_id][] = $v;
  434. } elseif (empty($goods_stcids_tmp[$v])) {//如果为一级分类而且分组不存在,则建立一个空分组数组
  435. $goods_stcids_tmp[$v] = array();
  436. }
  437. }
  438. foreach ($goods_stcids_tmp as $k => $v) {
  439. if (!empty($v) && count($v) > 0) {
  440. $goods_stcids_new = array_merge($goods_stcids_new, $v);
  441. } else {
  442. $goods_stcids_new[] = $k;
  443. }
  444. }
  445. }
  446. $result['store_class_goods'] = $goods_stcids_new;
  447. // F码
  448. if ($goodscommon_info['is_goodsfcode'] == 1) {
  449. $fcode_array = model('goodsfcode')->getGoodsfcodeList(array('goods_commonid' => $goodscommon_info['goods_commonid']));
  450. $result['fcode_array'] = $fcode_array;
  451. }
  452. ds_json_encode(10000, '', $result);
  453. }
  454. /**
  455. * @api {POST} api/Sellergoods/video_upload 上传商品视频
  456. * @apiVersion 1.0.0
  457. * @apiGroup Sellergoods
  458. *
  459. * @apiHeader {String} X-DS-KEY 卖家授权token
  460. *
  461. * @apiParam {File} refund_pic 图片
  462. * @apiParam {String} name 文件表单名
  463. *
  464. * @apiSuccess {String} code 返回码,10000为成功
  465. * @apiSuccess {String} message 返回消息
  466. * @apiSuccess {Object} result 返回数据
  467. * @apiSuccess {String} result.path 文件名
  468. * @apiSuccess {String} result.url 文件链接
  469. */
  470. public function video_upload() {
  471. $store_id = $this->store_info['store_id'];
  472. $save_name = $store_id . '_' . date('YmdHis') . rand(10000, 99999) . '.mp4';
  473. $file_name = input('post.name');
  474. $upload_path = ATTACH_GOODS . DIRECTORY_SEPARATOR . $store_id;
  475. $res = ds_upload_pic($upload_path, $file_name, $save_name, 'mp4');
  476. if ($res['code']) {
  477. $save_name = $res['data']['file_name'];
  478. $data = array();
  479. $data ['url'] = goods_video($save_name);
  480. $data ['name'] = $save_name;
  481. $goods_model = model('goods');
  482. $goods_model->addGoodsVideo(array(
  483. 'store_id' => $store_id,
  484. 'store_name' => $this->store_info['store_name'],
  485. 'goodsvideo_name' => $save_name,
  486. 'goodsvideo_add_time' => TIMESTAMP
  487. ));
  488. ds_json_encode(10000, '', array('url' => goods_video($save_name), 'path' => $save_name));
  489. } else {
  490. ds_json_encode(10001, $res['msg']);
  491. }
  492. }
  493. /**
  494. * @api {POST} api/Sellergoods/image_upload 上传商品图片
  495. * @apiVersion 1.0.0
  496. * @apiGroup Sellergoods
  497. *
  498. * @apiHeader {String} X-DS-KEY 卖家授权token
  499. *
  500. * @apiParam {File} refund_pic 图片
  501. * @apiParam {String} name 文件表单名
  502. *
  503. * @apiSuccess {String} code 返回码,10000为成功
  504. * @apiSuccess {String} message 返回消息
  505. * @apiSuccess {Object} result 返回数据
  506. * @apiSuccess {String} result.path 文件名
  507. * @apiSuccess {String} result.url 文件链接
  508. */
  509. public function image_upload() {
  510. // 判断图片数量是否超限
  511. $album_model = model('album');
  512. $album_limit = $this->store_grade['storegrade_album_limit'];
  513. if ($album_limit > 0) {
  514. $album_count = $album_model->getCount(array('store_id' => $this->store_info['store_id']));
  515. if ($album_count >= $album_limit) {
  516. ds_json_encode(10001, lang('store_goods_album_climit'));
  517. }
  518. }
  519. $class_info = $album_model->getOne(array('store_id' => $this->store_info['store_id'], 'aclass_isdefault' => 1), 'albumclass');
  520. $store_id = $this->store_info['store_id'];
  521. /**
  522. * 上传图片
  523. */
  524. $time=TIMESTAMP;
  525. //上传文件保存路径
  526. $upload_path = ATTACH_GOODS . '/' . $store_id . '/' . date('Ymd',$time);
  527. $save_name = $this->store_info['store_id'] . '_' . date('YmdHis',$time) . rand(10000, 99999);
  528. $file_name = input('post.name');
  529. $result = upload_albumpic($upload_path, $file_name, $save_name);
  530. if ($result['code'] == '10000') {
  531. $img_path = $result['result'];
  532. list($width, $height, $type, $attr) = getimagesize($img_path);
  533. $img_path = substr(strrchr($img_path, "/"), 1);
  534. } else {
  535. //未上传图片或出错不做后面处理
  536. ds_json_encode(10001, lang('ds_common_op_fail'));
  537. }
  538. // 存入相册
  539. $insert_array = array();
  540. $insert_array['apic_name'] = $img_path;
  541. $insert_array['apic_tag'] = '';
  542. $insert_array['aclass_id'] = $class_info['aclass_id'];
  543. $insert_array['apic_cover'] = $img_path;
  544. $insert_array['apic_size'] = intval($_FILES[$file_name]['size']);
  545. $insert_array['apic_spec'] = $width . 'x' . $height;
  546. $insert_array['apic_uploadtime'] = $time;
  547. $insert_array['store_id'] = $store_id;
  548. $result = model('album')->addAlbumpic($insert_array);
  549. // 整理为json格式
  550. ds_json_encode(10000, '', array('url' => goods_cthumb($img_path, 480, $this->store_info['store_id']), 'path' => $img_path));
  551. }
  552. /**
  553. * @api {POST} api/Sellergoods/add_spec 新增规格值
  554. * @apiVersion 1.0.0
  555. * @apiGroup Sellergoods
  556. *
  557. * @apiHeader {String} X-DS-KEY 卖家授权token
  558. *
  559. * @apiParam {String} name 规格值
  560. * @apiParam {Int} gc_id 商品分类ID
  561. * @apiParam {Int} sp_id 规格名ID
  562. *
  563. * @apiSuccess {String} code 返回码,10000为成功
  564. * @apiSuccess {String} message 返回消息
  565. * @apiSuccess {Object} result 返回数据
  566. * @apiSuccess {Int} result.value_id 规格值id
  567. */
  568. public function add_spec() {
  569. $name = trim(input('param.name'));
  570. $gc_id = intval(input('param.gc_id'));
  571. $sp_id = intval(input('param.sp_id'));
  572. if ($name == '' || $gc_id <= 0 || $sp_id <= 0) {
  573. ds_json_encode(10000, lang('param_error'));
  574. }
  575. $insert = array(
  576. 'spvalue_name' => $name, 'sp_id' => $sp_id, 'gc_id' => $gc_id, 'store_id' => $this->store_info['store_id'],
  577. 'spvalue_color' => null, 'spvalue_sort' => 0,
  578. );
  579. $value_id = model('spec')->addSpecvalue($insert);
  580. if ($value_id) {
  581. ds_json_encode(10000, '', array('value_id' => $value_id));
  582. } else {
  583. ds_json_encode(10001, lang('ds_common_op_fail'));
  584. }
  585. }
  586. /**
  587. * @api {POST} api/Sellergoods/save_goods 保存商品信息
  588. * @apiVersion 1.0.0
  589. * @apiGroup Sellergoods
  590. *
  591. * @apiHeader {String} X-DS-KEY 卖家授权token
  592. *
  593. * @apiParam {Int} commonid 商品公共ID
  594. * @apiParam {Int} class_id 商品分类ID
  595. * @apiParam {Object} goods 商品信息
  596. * @apiParam {String} goods.goods_name 商品名称
  597. * @apiParam {String} goods.goods_advword 商品广告
  598. * @apiParam {Int} goods.brand_id 商品品牌ID
  599. * @apiParam {String} goods.brand_name 商品品牌名称
  600. * @apiParam {String} goods.goods_image 商品图片
  601. * @apiParam {Float} goods.goods_price 商品价格
  602. * @apiParam {Float} goods.goods_marketprice 商品市场价
  603. * @apiParam {Float} goods.goods_costprice 商品成本价
  604. * @apiParam {Int} goods.goods_discount 商品折扣
  605. * @apiParam {String} goods.goods_serial 商品货号
  606. * @apiParam {Int} goods.goods_storage 商品库存
  607. * @apiParam {Int} goods.goods_storage_alarm 商品库存预警值
  608. * @apiParam {Int} goods.goods_commend 商品推荐(0否1是)
  609. * @apiParam {Int} goods.goods_state 商品状态(0下架1上架)
  610. * @apiParam {Int} goods.goods_shelftime 上架时间(unix时间戳)
  611. * @apiParam {Int} goods.goods_vat 是否开增值税发票(0否1是)
  612. * @apiParam {Int} goods.areaid_1 省ID
  613. * @apiParam {Int} goods.areaid_2 市ID
  614. * @apiParam {Int} goods.transport_id 售卖地区ID
  615. * @apiParam {String} goods.transport_title 售卖地区名称
  616. * @apiParam {Float} goods.goods_freight 商品运费
  617. * @apiParam {Int} goods.is_virtual 是否虚拟商品(0否1是)
  618. * @apiParam {Int} goods.virtual_indate 虚拟商品有效期(unix时间戳)
  619. * @apiParam {Int} goods.virtual_limit 虚拟商品购买上限(1-10)
  620. * @apiParam {Int} goods.virtual_invalid_refund 是否支持过期退款(0否1是)
  621. * @apiParam {Int} goods.is_goodsfcode 是否F码商品(0否1是)
  622. * @apiParam {Int} goods.is_appoint 是否预约商品(0否1是)
  623. * @apiParam {Int} goods.appoint_satedate 发售时间(unix时间戳)
  624. * @apiParam {Int[]} sgcate_id 店铺分类ID列表
  625. * @apiParam {Object} spec 商品规格(键为规格值id升序排列的字符串)
  626. * @apiParam {Int} spec.goods_id 商品ID
  627. * @apiParam {Float} spec.goods_price 商品价格
  628. * @apiParam {Float} spec.goods_marketprice 商品市场价
  629. * @apiParam {Int} spec.goods_storage 商品库存
  630. * @apiParam {Int} spec.goods_storage_alarm 库存预警值
  631. * @apiParam {String[]} spec.sp_value 商品规格值列表
  632. * @apiParam {Int} spec.color 颜色规格值ID
  633. * @apiParam {Int[]} attr 属性ID列表
  634. * @apiParam {Object[]} goods_body 商品详情
  635. * @apiParam {String} goods_body.mb_body.type 商品详情类型(image图片text文字)
  636. * @apiParam {String} goods_body.mb_body.value 商品详情值
  637. * @apiParam {String} result.goods.mb_body.value_url 商品详情图片链接
  638. * @apiParam {Object} sp_name (键为规格名id,值为规格名)
  639. * @apiParam {Object} sp_val (键为规格名id,值中的键为规格值id,值中的值为规格值)
  640. * @apiParam {Int} g_fccount F码数量
  641. * @apiParam {String} g_fcprefix F码前缀
  642. *
  643. * @apiSuccess {String} code 返回码,10000为成功
  644. * @apiSuccess {String} message 返回消息
  645. * @apiSuccess {Object} result 返回数据
  646. */
  647. public function save_goods() {
  648. $common_id = intval(input('param.commonid'));
  649. $if_add = $common_id ? false : true;
  650. $gc_id = intval(input('post.class_id'));
  651. // 验证商品分类是否存在且商品分类是否为最后一级
  652. $data = model('goodsclass')->getGoodsclassForCacheModel();
  653. if (!isset($data[$gc_id]) || isset($data[$gc_id]['child']) || isset($data[$gc_id]['childchild'])) {
  654. ds_json_encode(10001, lang('store_goods_index_again_choose_category1'));
  655. }
  656. // 三方店铺验证是否绑定了该分类
  657. if (!check_platform_store()) {
  658. //商品分类 提供批量显示所有分类插件
  659. $storebindclass_model = model('storebindclass');
  660. $goods_class = model('goodsclass')->getGoodsclassForCacheModel();
  661. $condition = array();
  662. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  663. $class_2 = isset($goods_class[$gc_id]['gc_parent_id']) ? $goods_class[$gc_id]['gc_parent_id'] : 0;
  664. $class_1 = isset($goods_class[$class_2]['gc_parent_id']) ? $goods_class[$class_2]['gc_parent_id'] : 0;
  665. $condition_class_1 = array(array('class_1', '=', ($class_1 > 0) ? $class_1 : (($class_2 > 0) ? $class_2 : $gc_id)));
  666. $condition_class_2 = array(array('class_2', '=', ($class_1 > 0) ? $class_2 : (($class_2 > 0) ? $gc_id : 0)));
  667. $condition_class_3 = array(array('class_3', '=', ($class_1 > 0 && $class_2 > 0) ? $gc_id : 0));
  668. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  669. if (empty($bind_info)) {
  670. $condition_class_3 = array(array('class_3', '=', 0));
  671. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  672. if (empty($bind_info)) {
  673. $condition_class_2 = array(array('class_2', '=', 0));
  674. $condition_class_3 = array(array('class_3', '=', 0));
  675. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  676. if (empty($bind_info)) {
  677. $condition_class_1 = array(array('class_1', '=', 0));
  678. $condition_class_2 = array(array('class_2', '=', 0));
  679. $condition_class_3 = array(array('class_3', '=', 0));
  680. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  681. if (empty($bind_info)) {
  682. ds_json_encode(10001, lang('store_goods_index_again_choose_category2'));
  683. }
  684. }
  685. }
  686. }
  687. }
  688. // 分类信息
  689. $goods_class = model('goodsclass')->getGoodsclassLineForTag(intval($gc_id));
  690. $goods_model = model('goods');
  691. $update_common = array();
  692. $update_common['goods_name'] = input('post.goods.goods_name');
  693. $update_common['goods_advword'] = input('post.goods.goods_advword');
  694. $update_common['gc_id'] = $gc_id;
  695. $update_common['gc_id_1'] = isset($goods_class['gc_id_1']) ? intval($goods_class['gc_id_1']) : 0;
  696. $update_common['gc_id_2'] = isset($goods_class['gc_id_2']) ? intval($goods_class['gc_id_2']) : 0;
  697. $update_common['gc_id_3'] = isset($goods_class['gc_id_3']) ? intval($goods_class['gc_id_3']) : 0;
  698. $update_common['gc_name'] = $goods_class['gctag_name'];
  699. $update_common['brand_id'] = input('post.goods.brand_id');
  700. $update_common['brand_name'] = input('post.goods.brand_name');
  701. $update_common['type_id'] = $goods_class['type_id'];
  702. $update_common['goods_image'] = input('post.goods.goods_image');
  703. $update_common['goodsvideo_name'] = input('post.goods.goodsvideo_name');
  704. $update_common['goods_price'] = floatval(input('post.goods.goods_price'));
  705. $update_common['goods_marketprice'] = floatval(input('post.goods.goods_marketprice'));
  706. $update_common['goods_costprice'] = floatval(input('post.goods.goods_costprice'));
  707. $update_common['goods_discount'] = floatval(input('post.goods.goods_discount'));
  708. $update_common['goods_serial'] = input('post.goods.goods_serial', '');
  709. $update_common['goods_storage_alarm'] = intval(input('post.goods.goods_storage_alarm'));
  710. $update_common['goods_attr'] = !empty(input('post.attr/a')) ? serialize(input('post.attr/a')) : '';
  711. // 序列化保存手机端商品描述数据
  712. $mobile_body = serialize(input('post.goods_body/a'));
  713. $update_common['mobile_body'] = $mobile_body;
  714. $update_common['goods_commend'] = intval(input('post.goods.goods_commend'));
  715. $update_common['goods_state'] = ($this->store_info['store_state'] != 1) ? 0 : intval(input('post.goods.goods_state')); // 店铺关闭时,商品下架
  716. $update_common['goods_shelftime'] = input('post.goods.goods_shelftime', 0);
  717. $update_common['goods_verify'] = (config('ds_config.goods_verify') == 1) ? 10 : 1;
  718. $update_common['spec_name'] = !empty(input('post.spec/a')) ? serialize(input('post.sp_name/a')) : serialize(null);
  719. $update_common['spec_value'] = !empty(input('post.spec/a')) ? serialize(input('post.sp_val/a')) : serialize(null);
  720. $update_common['goods_vat'] = intval(input('post.goods.goods_vat'));
  721. $update_common['areaid_1'] = intval(input('post.goods.areaid_1'));
  722. $update_common['areaid_2'] = intval(input('post.goods.areaid_2'));
  723. $update_common['transport_id'] = intval(input('post.goods.transport_id')); // 售卖区域
  724. $update_common['transport_title'] = input('post.goods.transport_title');
  725. $update_common['goods_freight'] = floatval(input('post.goods.goods_freight'));
  726. //查询店铺商品分类
  727. $goods_stcids_arr = array();
  728. $sgcate_id_array = input('post.sgcate_id/a'); #获取数组
  729. if (!empty($sgcate_id_array)) {
  730. $sgcate_id_arr = array();
  731. foreach ($sgcate_id_array as $k => $v) {
  732. if ($v) {
  733. $sgcate_id_arr[] = intval($v);
  734. }
  735. }
  736. if (!empty($sgcate_id_arr)) {
  737. $sgcate_id_arr = array_unique($sgcate_id_arr);
  738. $store_goods_class = model('storegoodsclass')->getStoregoodsclassList(array(array('store_id', '=', $this->store_info['store_id']), array('storegc_id', 'in', $sgcate_id_arr), array('storegc_state', '=', '1')));
  739. if (!empty($store_goods_class)) {
  740. foreach ($store_goods_class as $k => $v) {
  741. if ($v['storegc_id'] > 0) {
  742. $goods_stcids_arr[] = $v['storegc_id'];
  743. }
  744. if ($v['storegc_parent_id'] > 0) {
  745. $goods_stcids_arr[] = $v['storegc_parent_id'];
  746. }
  747. }
  748. $goods_stcids_arr = array_unique($goods_stcids_arr);
  749. sort($goods_stcids_arr);
  750. }
  751. }
  752. }
  753. if (empty($goods_stcids_arr)) {
  754. $update_common['goods_stcids'] = '';
  755. } else {
  756. $update_common['goods_stcids'] = ',' . implode(',', $goods_stcids_arr) . ',';
  757. }
  758. $update_common['is_virtual'] = intval(input('post.goods.is_virtual'));
  759. $update_common['virtual_type'] = $update_common['is_virtual']?intval(input('post.goods.virtual_type')):0;
  760. $update_common['virtual_indate'] = input('post.goods.virtual_indate'); // 当天的最后一秒结束
  761. $update_common['virtual_limit'] = intval(input('post.goods.virtual_limit')) > 10 || intval(input('post.goods.virtual_limit')) < 0 ? 10 : intval(input('post.goods.virtual_limit'));
  762. $update_common['virtual_invalid_refund'] = intval(input('post.goods.virtual_invalid_refund'));
  763. $update_common['is_goodsfcode'] = $update_common['is_virtual'] ? 0 : intval(input('post.goods.is_goodsfcode'));
  764. $update_common['is_appoint'] = $update_common['is_virtual'] ? 0 : intval(input('post.goods.is_appoint')); // 只有库存为零的商品可以预约
  765. $update_common['appoint_satedate'] = $update_common['is_appoint'] == 1 ? input('post.goods.appoint_satedate') : ''; // 预约商品的销售时间
  766. $update_common['is_platform_store'] = in_array($this->store_info['store_id'], model('store')->getOwnShopIds()) ? 1 : 0;
  767. if ($update_common['is_virtual']) {
  768. if (!$update_common['virtual_indate'] && $update_common['virtual_type']==0) {
  769. ds_json_encode(10001, lang('prompt_information9'));
  770. }
  771. if (!$update_common['virtual_limit'] || $update_common['virtual_limit'] < 1 || $update_common['virtual_limit'] > 10) {
  772. ds_json_encode(10001, lang('virtual_goods_instructions5'));
  773. }
  774. }
  775. if ($update_common['is_appoint']) {
  776. if (!$update_common['appoint_satedate']) {
  777. ds_json_encode(10001, lang('prompt_information9'));
  778. }
  779. }
  780. if (!$if_add) {//编辑
  781. $sellergoodsonline_validate = ds_validate('sellergoodsonline');
  782. if (!$sellergoodsonline_validate->scene('edit_save_goods')->check($update_common)) {
  783. ds_json_encode('10001', $sellergoodsonline_validate->getError());
  784. }
  785. } else {
  786. // 保存数据
  787. $update_common['store_id'] = $this->store_info['store_id'];
  788. $update_common['store_name'] = $this->store_info['store_name'];
  789. $update_common['goods_addtime'] = TIMESTAMP;
  790. $goods_validate = ds_validate('sellergoodsadd');
  791. if (!$goods_validate->scene('save_goods')->check($update_common)) {
  792. ds_json_encode(10001, $goods_validate->getError());
  793. }
  794. }
  795. // 开始事务
  796. Db::startTrans();
  797. try {
  798. $goods_model->lock=true;
  799. if ($if_add) {
  800. $common_id = $goods_model->addGoodsCommon($update_common);
  801. if (!$common_id) {
  802. throw new \think\Exception(lang('store_goods_index_goods_add_fail'), 10006);
  803. }
  804. }
  805. $goodsgift_model = model('goodsgift');
  806. // 清除原有规格数据
  807. $type_model = model('type');
  808. $type_model->delGoodsAttr(array('goods_commonid' => $common_id));
  809. // 更新商品规格
  810. $goodsid_array = array();
  811. $colorid_array = array();
  812. $spec_array = input('post.spec/a'); #获取数组
  813. if (is_array($spec_array) && !empty($spec_array)) {
  814. foreach ($spec_array as $value) {
  815. if ($value) {
  816. $value['goods_price'] = abs(floatval($value['goods_price']));
  817. $value['goods_marketprice'] = isset($value['goods_marketprice']) ? abs(floatval($value['goods_marketprice'])) : 0;
  818. $value['goods_weight'] = isset($value['goods_weight']) ? abs(floatval($value['goods_weight'])) : 0;
  819. $value['goods_storage'] = abs(intval($value['goods_storage']));
  820. $value['goods_storage_alarm'] = abs(intval($value['goods_storage_alarm']));
  821. if (!$value['goods_price']) {
  822. throw new \think\Exception(lang('store_goods_index_goods_price_null'), 10006);
  823. }
  824. if ($value['goods_price'] > $value['goods_marketprice'] && $value['goods_marketprice'] > 0) {
  825. throw new \think\Exception(lang('not_higher_than'), 10006);
  826. }
  827. $goods_info = $goods_model->getGoodsInfo(array('goods_id' => $value['goods_id'], 'goods_commonid' => $common_id, 'store_id' => $this->store_info['store_id']), 'goods_id');
  828. if (!empty($goods_info)) {
  829. $goods_id = $goods_info['goods_id'];
  830. $update = array();
  831. $update['goods_commonid'] = $common_id;
  832. $update['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']);
  833. $update['goods_advword'] = $update_common['goods_advword'];
  834. $update['store_id'] = $this->store_info['store_id'];
  835. $update['store_name'] = $this->store_info['store_name'];
  836. $update['gc_id'] = $update_common['gc_id'];
  837. $update['gc_id_1'] = $update_common['gc_id_1'];
  838. $update['gc_id_2'] = $update_common['gc_id_2'];
  839. $update['gc_id_3'] = $update_common['gc_id_3'];
  840. $update['brand_id'] = $update_common['brand_id'];
  841. $update['goods_price'] = $value['goods_price'];
  842. $update['goods_marketprice'] = (!isset($value['goods_marketprice']) || $value['goods_marketprice'] == 0) ? $update_common['goods_marketprice'] : $value['goods_marketprice'];
  843. $update['goods_serial'] = isset($value['goods_serial']) ? $value['goods_serial'] : '';
  844. $update['goods_storage_alarm'] = isset($value['goods_storage_alarm']) ? intval($value['goods_storage_alarm']) : 0;
  845. $update['goods_spec'] = serialize($value['sp_value']);
  846. $update['goods_storage'] = $value['goods_storage'];
  847. $update['goods_weight'] = isset($value['goods_weight']) ? $value['goods_weight'] : 0;
  848. $update['goods_state'] = $update_common['goods_state'];
  849. $update['goods_verify'] = $update_common['goods_verify'];
  850. $update['goods_edittime'] = TIMESTAMP;
  851. $update['areaid_1'] = $update_common['areaid_1'];
  852. $update['areaid_2'] = $update_common['areaid_2'];
  853. $update['color_id'] = isset($value['color']) ? intval($value['color']) : '';
  854. $update['transport_id'] = $update_common['transport_id'];
  855. $update['goods_freight'] = $update_common['goods_freight'];
  856. $update['goods_vat'] = $update_common['goods_vat'];
  857. $update['goods_commend'] = $update_common['goods_commend'];
  858. $update['goods_stcids'] = $update_common['goods_stcids'];
  859. $update['is_virtual'] = $update_common['is_virtual'];
  860. $update['virtual_indate'] = $update_common['virtual_indate'];
  861. $update['virtual_limit'] = $update_common['virtual_limit'];
  862. $update['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  863. $update['is_goodsfcode'] = $update_common['is_goodsfcode'];
  864. $update['is_appoint'] = $update_common['is_appoint'];
  865. switch($update_common['virtual_type']){
  866. case 1:
  867. $update['virtual_content'] = $value['vc_card'];
  868. $res=$goods_model->getAvailableGoodsCard(array_merge($update,array('goods_id'=>$goods_info['goods_id'])));
  869. if($res['code']){
  870. $update['goods_storage'] = $res['data']['card_num'];
  871. }else{
  872. $update['goods_storage'] = 0;
  873. }
  874. break;
  875. case 2:
  876. $update['virtual_content'] = $value['vc_pan'];
  877. $update['goods_storage'] = 1;
  878. break;
  879. case 3:
  880. $update['virtual_content'] = $value['vc_file'];
  881. $update['goods_storage'] = 1;
  882. break;
  883. default:
  884. $update['virtual_content'] = '';
  885. }
  886. // 虚拟商品不能有赠品
  887. if ($update_common['is_virtual'] == 1) {
  888. $update['is_have_gift'] = 0;
  889. $goodsgift_model->delGoodsgift(array('goods_id' => $goods_id));
  890. }
  891. $goods_model->editGoodsById($update, $goods_id);
  892. } else {
  893. $insert = array();
  894. $insert['goods_commonid'] = $common_id;
  895. $insert['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']);
  896. $insert['goods_advword'] = $update_common['goods_advword'];
  897. $insert['store_id'] = $this->store_info['store_id'];
  898. $insert['store_name'] = $this->store_info['store_name'];
  899. $insert['gc_id'] = $update_common['gc_id'];
  900. $insert['gc_id_1'] = $update_common['gc_id_1'];
  901. $insert['gc_id_2'] = $update_common['gc_id_2'];
  902. $insert['gc_id_3'] = $update_common['gc_id_3'];
  903. $insert['brand_id'] = $update_common['brand_id'];
  904. $insert['goods_price'] = $value['goods_price'];
  905. $insert['goods_promotion_price'] = $value['goods_price'];
  906. $insert['goods_marketprice'] = (!isset($value['goods_marketprice']) || $value['goods_marketprice'] == 0) ? $update_common['goods_marketprice'] : $value['goods_marketprice'];
  907. $insert['goods_serial'] = isset($value['goods_serial']) ? $value['goods_serial'] : '';
  908. $insert['goods_storage_alarm'] = isset($value['goods_storage_alarm']) ? intval($value['goods_storage_alarm']) : 0;
  909. $insert['goods_spec'] = serialize($value['sp_value']);
  910. $insert['goods_storage'] = $value['goods_storage'];
  911. $insert['goods_weight'] = isset($value['goods_weight']) ? $value['goods_weight'] : 0;
  912. $insert['goods_image'] = $update_common['goods_image'];
  913. $insert['goods_state'] = $update_common['goods_state'];
  914. $insert['goods_verify'] = $update_common['goods_verify'];
  915. $insert['goods_addtime'] = TIMESTAMP;
  916. $insert['goods_edittime'] = TIMESTAMP;
  917. $insert['areaid_1'] = $update_common['areaid_1'];
  918. $insert['areaid_2'] = $update_common['areaid_2'];
  919. $insert['color_id'] = isset($value['color']) ? intval($value['color']) : '';
  920. $insert['transport_id'] = $update_common['transport_id'];
  921. $insert['goods_freight'] = $update_common['goods_freight'];
  922. $insert['goods_vat'] = $update_common['goods_vat'];
  923. $insert['goods_commend'] = $update_common['goods_commend'];
  924. $insert['goods_stcids'] = $update_common['goods_stcids'];
  925. $insert['is_virtual'] = $update_common['is_virtual'];
  926. $insert['virtual_indate'] = $update_common['virtual_indate'];
  927. $insert['virtual_limit'] = $update_common['virtual_limit'];
  928. $insert['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  929. $insert['is_goodsfcode'] = $update_common['is_goodsfcode'];
  930. $insert['is_appoint'] = $update_common['is_appoint'];
  931. $insert['is_platform_store'] = $update_common['is_platform_store'];
  932. switch($update_common['virtual_type']){
  933. case 1:
  934. $insert['virtual_content'] = $value['vc_card'];
  935. $card_list=explode("\r\n",$insert['virtual_content']);
  936. $insert['goods_storage'] = count($card_list);
  937. break;
  938. case 2:
  939. $insert['virtual_content'] = $value['vc_pan'];
  940. $insert['goods_storage'] = 1;
  941. break;
  942. case 3:
  943. $insert['virtual_content'] = $value['vc_file'];
  944. $insert['goods_storage'] = 1;
  945. break;
  946. default:
  947. $insert['virtual_content'] = '';
  948. }
  949. $goods_id = $goods_model->addGoods($insert);
  950. }
  951. $goodsid_array[] = intval($goods_id);
  952. $colorid_array[] = isset($value['color']) ? intval($value['color']) : '';
  953. $type_model->addGoodsType($goods_id, $common_id, array('cate_id' => $gc_id, 'type_id' => $goods_class['type_id'], 'attr' => input('post.attr/a')));
  954. }
  955. }
  956. } else {
  957. $goods_info = $goods_model->getGoodsInfo(array('goods_spec' => serialize(null), 'goods_commonid' => $common_id, 'store_id' => $this->store_info['store_id']), 'goods_id');
  958. if (!empty($goods_info)) {
  959. $goods_id = $goods_info['goods_id'];
  960. $update = array();
  961. $update['goods_commonid'] = $common_id;
  962. $update['goods_name'] = $update_common['goods_name'];
  963. $update['goods_advword'] = $update_common['goods_advword'];
  964. $update['store_id'] = $this->store_info['store_id'];
  965. $update['store_name'] = $this->store_info['store_name'];
  966. $update['gc_id'] = $update_common['gc_id'];
  967. $update['gc_id_1'] = $update_common['gc_id_1'];
  968. $update['gc_id_2'] = $update_common['gc_id_2'];
  969. $update['gc_id_3'] = $update_common['gc_id_3'];
  970. $update['brand_id'] = $update_common['brand_id'];
  971. $update['goods_price'] = $update_common['goods_price'];
  972. $update['goods_marketprice'] = $update_common['goods_marketprice'];
  973. $update['goods_serial'] = $update_common['goods_serial'];
  974. $update['goods_storage_alarm'] = $update_common['goods_storage_alarm'];
  975. $update['goods_spec'] = serialize(null);
  976. $update['goods_storage'] = intval(input('post.goods.goods_storage'));
  977. $update['goods_weight'] = floatval(input('post.goods.goods_weight'));
  978. $update['goods_state'] = $update_common['goods_state'];
  979. $update['goods_verify'] = $update_common['goods_verify'];
  980. $update['goods_edittime'] = TIMESTAMP;
  981. $update['areaid_1'] = $update_common['areaid_1'];
  982. $update['areaid_2'] = $update_common['areaid_2'];
  983. $update['color_id'] = 0;
  984. $update['transport_id'] = $update_common['transport_id'];
  985. $update['goods_freight'] = $update_common['goods_freight'];
  986. $update['goods_vat'] = $update_common['goods_vat'];
  987. $update['goods_commend'] = $update_common['goods_commend'];
  988. $update['goods_stcids'] = $update_common['goods_stcids'];
  989. $update['is_virtual'] = $update_common['is_virtual'];
  990. $update['virtual_indate'] = $update_common['virtual_indate'];
  991. $update['virtual_limit'] = $update_common['virtual_limit'];
  992. $update['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  993. $update['is_goodsfcode'] = $update_common['is_goodsfcode'];
  994. $update['is_appoint'] = $update_common['is_appoint'];
  995. switch($update_common['virtual_type']){
  996. case 1:
  997. $update['virtual_content'] = input('post.goods.vc_card');
  998. $res=$goods_model->getAvailableGoodsCard(array_merge($update,array('goods_id'=>$goods_info['goods_id'])));
  999. if($res['code']){
  1000. $update['goods_storage'] = $res['data']['card_num'];
  1001. }else{
  1002. $update['goods_storage'] = 0;
  1003. }
  1004. break;
  1005. case 2:
  1006. $update['virtual_content'] = input('post.goods.vc_pan');
  1007. $update['goods_storage'] = 1;
  1008. break;
  1009. case 3:
  1010. $update['virtual_content'] = input('post.goods.vc_file');
  1011. $update['goods_storage'] = 1;
  1012. break;
  1013. default:
  1014. $update['virtual_content'] = '';
  1015. }
  1016. if ($update_common['is_virtual'] == 1) {
  1017. $update['is_have_gift'] = 0;
  1018. $goodsgift_model->delGoodsgift(array('goods_id' => $goods_id));
  1019. }
  1020. $goods_model->editGoodsById($update, $goods_id);
  1021. } else {
  1022. $insert = array();
  1023. $insert['goods_commonid'] = $common_id;
  1024. $insert['goods_name'] = $update_common['goods_name'];
  1025. $insert['goods_advword'] = $update_common['goods_advword'];
  1026. $insert['store_id'] = $this->store_info['store_id'];
  1027. $insert['store_name'] = $this->store_info['store_name'];
  1028. $insert['gc_id'] = $update_common['gc_id'];
  1029. $insert['gc_id_1'] = $update_common['gc_id_1'];
  1030. $insert['gc_id_2'] = $update_common['gc_id_2'];
  1031. $insert['gc_id_3'] = $update_common['gc_id_3'];
  1032. $insert['brand_id'] = $update_common['brand_id'];
  1033. $insert['goods_price'] = $update_common['goods_price'];
  1034. $insert['goods_promotion_price'] = $update_common['goods_price'];
  1035. $insert['goods_marketprice'] = $update_common['goods_marketprice'];
  1036. $insert['goods_serial'] = $update_common['goods_serial'];
  1037. $insert['goods_storage_alarm'] = $update_common['goods_storage_alarm'];
  1038. $insert['goods_spec'] = serialize(null);
  1039. $insert['goods_storage'] = intval(input('post.goods.goods_storage'));
  1040. $insert['goods_weight'] = floatval(input('post.goods.goods_weight'));
  1041. $insert['goods_image'] = $update_common['goods_image'];
  1042. $insert['goods_state'] = $update_common['goods_state'];
  1043. $insert['goods_verify'] = $update_common['goods_verify'];
  1044. $insert['goods_addtime'] = TIMESTAMP;
  1045. $insert['goods_edittime'] = TIMESTAMP;
  1046. $insert['areaid_1'] = $update_common['areaid_1'];
  1047. $insert['areaid_2'] = $update_common['areaid_2'];
  1048. $insert['color_id'] = 0;
  1049. $insert['transport_id'] = $update_common['transport_id'];
  1050. $insert['goods_freight'] = $update_common['goods_freight'];
  1051. $insert['goods_vat'] = $update_common['goods_vat'];
  1052. $insert['goods_commend'] = $update_common['goods_commend'];
  1053. $insert['goods_stcids'] = $update_common['goods_stcids'];
  1054. $insert['is_virtual'] = $update_common['is_virtual'];
  1055. $insert['virtual_indate'] = $update_common['virtual_indate'];
  1056. $insert['virtual_limit'] = $update_common['virtual_limit'];
  1057. $insert['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  1058. $insert['is_goodsfcode'] = $update_common['is_goodsfcode'];
  1059. $insert['is_appoint'] = $update_common['is_appoint'];
  1060. $insert['is_platform_store'] = $update_common['is_platform_store'];
  1061. switch($update_common['virtual_type']){
  1062. case 1:
  1063. $insert['virtual_content'] = input('post.goods.vc_card');
  1064. $card_list=explode("\r\n",$insert['virtual_content']);
  1065. $insert['goods_storage'] = count($card_list);
  1066. break;
  1067. case 2:
  1068. $insert['virtual_content'] = input('post.goods.vc_pan');
  1069. $insert['goods_storage'] = 1;
  1070. break;
  1071. case 3:
  1072. $insert['virtual_content'] = input('post.goods.vc_file');
  1073. $insert['goods_storage'] = 1;
  1074. break;
  1075. default:
  1076. $insert['virtual_content'] = '';
  1077. }
  1078. $goods_id = $goods_model->addGoods($insert);
  1079. }
  1080. $goodsid_array[] = intval($goods_id);
  1081. $colorid_array[] = 0;
  1082. $type_model->addGoodsType($goods_id, $common_id, array('cate_id' => $gc_id, 'type_id' => $goods_class['type_id'], 'attr' => input('post.attr/a')));
  1083. }
  1084. // 清理商品数据
  1085. $goods_model->delGoods(array(array('goods_id', 'not in', $goodsid_array), array('goods_commonid', '=', $common_id), array('store_id', '=', $this->store_info['store_id'])));
  1086. // 清理商品图片表
  1087. $colorid_array = array_unique($colorid_array);
  1088. $goods_model->delGoodsImages(array(array('goods_commonid', '=', $common_id), array('color_id', 'not in', $colorid_array)));
  1089. // 更新商品默认主图
  1090. $default_image_list = $goods_model->getGoodsImageList(array('goods_commonid' => $common_id, 'goodsimage_isdefault' => 1), 'color_id,goodsimage_url');
  1091. if (!empty($default_image_list)) {
  1092. foreach ($default_image_list as $val) {
  1093. $goods_model->editGoods(array('goods_image' => $val['goodsimage_url']), array('goods_commonid' => $common_id, 'color_id' => $val['color_id']));
  1094. }
  1095. }
  1096. // 商品加入上架队列
  1097. if (!empty(input('post.goods.goods_shelftime'))) {
  1098. $selltime = input('post.goods.goods_shelftime');
  1099. if ($selltime > TIMESTAMP) {
  1100. $this->addcron(array('cron_exetime' => $selltime, 'cron_value' => serialize(intval($common_id)), 'cron_type' => 'editProducesOnline'), true);
  1101. }
  1102. }
  1103. // 添加操作日志
  1104. $this->recordSellerlog('编辑商品,平台货号:' . $common_id);
  1105. if ($update_common['is_virtual'] == 1 || $update_common['is_goodsfcode'] == 1) {
  1106. // 如果是特殊商品清理促销活动,抢购、秒杀、组合销售
  1107. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'clearSpecialGoodsPromotion','cron_value'=>serialize(array('goods_commonid' => $common_id, 'goodsid_array' => $goodsid_array))));
  1108. } else {
  1109. // 更新商品促销价格
  1110. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'updateGoodsPromotionPriceByGoodsCommonId','cron_value'=>serialize($common_id)));
  1111. }
  1112. // 生成F码
  1113. if ($update_common['is_goodsfcode'] == 1) {
  1114. model('goodsfcode')->createGoodsfcode(array('goods_commonid' => $common_id, 'goodsfcode_count' => intval(input('post.g_fccount')), 'goodsfcode_prefix' => input('post.g_fcprefix')));
  1115. }
  1116. if (!$if_add) {
  1117. $return = $goods_model->editGoodsCommon($update_common, array('goods_commonid' => $common_id, 'store_id' => $this->store_info['store_id']));
  1118. }
  1119. } catch (\Exception $e) {
  1120. Db::rollback();
  1121. ds_json_encode(10001, $e->getMessage());
  1122. }
  1123. Db::commit();
  1124. ds_json_encode(10000, lang('ds_common_op_succ'), array('commonid' => $common_id));
  1125. }
  1126. /**
  1127. * @api {POST} api/Sellergoods/edit_image 获取商品图片
  1128. * @apiVersion 1.0.0
  1129. * @apiGroup Sellergoods
  1130. *
  1131. * @apiHeader {String} X-DS-KEY 卖家授权token
  1132. *
  1133. * @apiParam {Int} commonid 商品公共ID
  1134. *
  1135. * @apiSuccess {String} code 返回码,10000为成功
  1136. * @apiSuccess {String} message 返回消息
  1137. * @apiSuccess {Object} result 返回数据
  1138. * @apiSuccess {Object} result.spec_value 规格列表(键为规格名id,值中的键为规格值id,值中的值为规格值)
  1139. * @apiSuccess {Object} result.img 图片列表(键为规格值id,值为图片列表)
  1140. * @apiSuccess {String} result.img.goodsimage_full_url 图片链接
  1141. * @apiSuccess {Int} result.img.goodsimage_isdefault 是否默认(0否1是)
  1142. * @apiSuccess {String} result.img.goodsimage_url 图片名称
  1143. * @apiSuccess {Object[]} result.value_array 规格值列表
  1144. * @apiSuccess {Int} result.value_array.spvalue_id 规格值id
  1145. * @apiSuccess {String} result.value_array.spvalue_name 规格值
  1146. */
  1147. public function edit_image() {
  1148. $result = array();
  1149. $common_id = intval(input('param.commonid'));
  1150. if ($common_id <= 0) {
  1151. ds_json_encode(10001, lang('param_error'));
  1152. }
  1153. $goods_model = model('goods');
  1154. $common_list = $goods_model->getGoodsCommonInfoByID($common_id);
  1155. if ($common_list['store_id'] != $this->store_info['store_id'] || $common_list['goods_lock'] == 1) {
  1156. ds_json_encode(10001, lang('goods_not_exist_or_lock'));
  1157. }
  1158. $spec_value = unserialize($common_list['spec_value']);
  1159. $result['spec_value'] = $spec_value;
  1160. $image_list = $goods_model->getGoodsImageList(array('goods_commonid' => $common_id));
  1161. $image_list = array_under_reset($image_list, 'color_id', 2);
  1162. $img_array = $goods_model->getGoodsList(array('goods_commonid' => $common_id), '*', 'color_id');
  1163. $image_array = array();
  1164. // 整理,更具id查询颜色名称
  1165. if (!empty($img_array)) {
  1166. foreach ($img_array as $val) {
  1167. if (isset($image_list[$val['color_id']])) {
  1168. $image_array[$val['color_id']] = $image_list[$val['color_id']];
  1169. foreach ($image_array[$val['color_id']] as $k => $v) {
  1170. $image_array[$val['color_id']][$k]['goodsimage_full_url'] = goods_cthumb($v['goodsimage_url'], 240);
  1171. }
  1172. } else {
  1173. $image_array[$val['color_id']][0]['goodsimage_url'] = $val['goods_image'];
  1174. $image_array[$val['color_id']][0]['goodsimage_full_url'] = goods_cthumb($val['goods_image'], 240);
  1175. $image_array[$val['color_id']][0]['goodsimage_isdefault'] = 1;
  1176. }
  1177. $colorid_array[] = $val['color_id'];
  1178. }
  1179. }
  1180. $result['img'] = $image_array;
  1181. $spec_model = model('spec');
  1182. $value_array = $spec_model->getSpecvalueList(array(array('spvalue_id', 'in', $colorid_array), array('store_id', '=', $this->store_info['store_id'])), 'spvalue_id,spvalue_name');
  1183. if (empty($value_array)) {
  1184. $value_array[] = array('spvalue_id' => '0', 'spvalue_name' => lang('no_color'));
  1185. }
  1186. $result['value_array'] = $value_array;
  1187. ds_json_encode(10000, '', $result);
  1188. }
  1189. /**
  1190. * @api {POST} api/Sellergoods/save_image 保存商品图片
  1191. * @apiVersion 1.0.0
  1192. * @apiGroup Sellergoods
  1193. *
  1194. * @apiHeader {String} X-DS-KEY 卖家授权token
  1195. *
  1196. * @apiParam {Int} commonid 商品公共ID
  1197. * @apiParam {Object[]} img 图片列表
  1198. * @apiParam {String} img.goodsimage_full_url 图片链接
  1199. * @apiParam {Int} img.goodsimage_isdefault 是否默认(0否1是)
  1200. * @apiParam {String} img.goodsimage_url 图片名称
  1201. *
  1202. * @apiSuccess {String} code 返回码,10000为成功
  1203. * @apiSuccess {String} message 返回消息
  1204. * @apiSuccess {Object} result 返回数据
  1205. *
  1206. */
  1207. public function save_image() {
  1208. $common_id = intval(input('param.commonid'));
  1209. $img_array = input('post.img/a'); #获取数组
  1210. if ($common_id <= 0 || empty($img_array)) {
  1211. ds_json_encode(10001, lang('param_error'));
  1212. }
  1213. $goods_model = model('goods');
  1214. $common_list = $goods_model->getGoodsCommonInfoByID($common_id);
  1215. if ($common_list['store_id'] != $this->store_info['store_id'] || $common_list['goods_lock'] == 1) {
  1216. ds_json_encode(10001, lang('goods_not_exist_or_lock'));
  1217. }
  1218. // 删除原有图片信息
  1219. $goods_model->delGoodsImages(array('goods_commonid' => $common_id, 'store_id' => $this->store_info['store_id']));
  1220. // 保存
  1221. $insert_array = array();
  1222. foreach ($img_array as $key => $value) {
  1223. $k = 0;
  1224. foreach ($value as $v) {
  1225. if ($v['goodsimage_url'] == '') {
  1226. continue;
  1227. }
  1228. // 商品默认主图
  1229. $update_array = array(); // 更新商品主图
  1230. $condition = array();
  1231. $update_array['goods_image'] = $v['goodsimage_url'];
  1232. $condition[] = array('goods_commonid', '=', $common_id);
  1233. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  1234. $condition[] = array('color_id', '=', $key);
  1235. if ($k == 0) {
  1236. $update_array['goods_image'] = $v['goodsimage_url'];
  1237. $condition[] = array('goods_commonid', '=', $common_id);
  1238. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  1239. $condition[] = array('color_id', '=', $key);
  1240. // 更新商品主图
  1241. $goods_model->editGoods($update_array, $condition);
  1242. }
  1243. $tmp_insert = array();
  1244. $tmp_insert['goods_commonid'] = $common_id;
  1245. $tmp_insert['store_id'] = $this->store_info['store_id'];
  1246. $tmp_insert['color_id'] = $key;
  1247. $tmp_insert['goodsimage_url'] = $v['goodsimage_url'];
  1248. $tmp_insert['goodsimage_sort'] = $k;
  1249. $tmp_insert['goodsimage_isdefault'] = ($k == 0) ? 1 : 0;
  1250. $insert_array[] = $tmp_insert;
  1251. $k++;
  1252. }
  1253. }
  1254. if (!empty($insert_array)) {
  1255. $rs = $goods_model->addGoodsImagesAll($insert_array);
  1256. if ($rs) {
  1257. // 添加操作日志
  1258. $this->recordSellerlog('编辑商品,平台货号:' . $common_id);
  1259. ds_json_encode(10000, lang('ds_common_op_succ'));
  1260. } else {
  1261. ds_json_encode(10001, lang('ds_common_op_fail'));
  1262. }
  1263. } else {
  1264. ds_json_encode(10000, lang('ds_common_op_succ'));
  1265. }
  1266. }
  1267. /**
  1268. * @api {POST} api/Sellergoods/goods_class 获取经营分类
  1269. * @apiVersion 1.0.0
  1270. * @apiGroup Sellergoods
  1271. *
  1272. * @apiHeader {String} X-DS-KEY 卖家授权token
  1273. *
  1274. *
  1275. * @apiSuccess {String} code 返回码,10000为成功
  1276. * @apiSuccess {String} message 返回消息
  1277. * @apiSuccess {Object} result 返回数据
  1278. * @apiSuccess {Int} result.bind_all 是否绑定全部分类(0否1是)
  1279. * @apiSuccess {Object[]} result.class_list 商品分类列表
  1280. * @apiSuccess {Int} result.class_list.id 分类ID
  1281. * @apiSuccess {String} result.class_list.value 分类名称
  1282. * @apiSuccess {Object[]} result.class_list.children 子分类列表
  1283. *
  1284. */
  1285. public function goods_class() {
  1286. $bind_all = false;
  1287. $store_bind_class_list = array();
  1288. if ($this->store_info['is_platform_store'] && $this->store_info['bind_all_gc']) {
  1289. $bind_all = true;
  1290. } else {
  1291. $storebindclass_model = model('storebindclass');
  1292. if ($storebindclass_model->getStorebindclassInfo(array(array('class_1&class_2&class_3', '=', 0), array('store_id', '=', $this->store_info['store_id']), array('storebindclass_state', 'in', array(1, 2))))) {
  1293. $bind_all = true;
  1294. } else {
  1295. $temp = $storebindclass_model->getStorebindclassList(array(array('store_id', '=', $this->store_info['store_id']), array('storebindclass_state', 'in', array(1, 2))), null);
  1296. $class_1_ids = array();
  1297. $class_2_ids = array();
  1298. $class_3_ids = array();
  1299. foreach ($temp as $class_info) {
  1300. if ($class_info['class_3'] == 0) {
  1301. if ($class_info['class_2'] == 0) {
  1302. $class_1_ids[] = $class_info['class_1'];
  1303. } else {
  1304. $class_2_ids[] = $class_info['class_2'];
  1305. }
  1306. } else {
  1307. $class_3_ids[] = $class_info['class_3'];
  1308. }
  1309. }
  1310. $goodsclass_list = array();
  1311. if (!empty($class_1_ids)) {
  1312. $class_1_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $class_1_ids)));
  1313. $goodsclass_list = array_merge($goodsclass_list, $class_1_list);
  1314. $temp_2 = Db::name('goodsclass')->where(array(array('gc_parent_id', 'in', $class_1_ids)))->column('gc_id');
  1315. if (!empty($temp_2)) {
  1316. $class_2_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $temp_2)));
  1317. $goodsclass_list = array_merge($goodsclass_list, $class_2_list);
  1318. $temp_3 = Db::name('goodsclass')->where(array(array('gc_parent_id', 'in', $temp_2)))->column('gc_id');
  1319. if (!empty($temp_3)) {
  1320. $class_3_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $temp_3)));
  1321. $goodsclass_list = array_merge($goodsclass_list, $class_3_list);
  1322. }
  1323. }
  1324. }
  1325. if (!empty($class_2_ids)) {
  1326. $temp_1 = Db::name('goodsclass')->where(array(array('gc_id', 'in', $class_2_ids)))->column('gc_parent_id');
  1327. $class_1_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $temp_1)));
  1328. $goodsclass_list = array_merge($goodsclass_list, $class_1_list);
  1329. $class_2_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $class_2_ids)));
  1330. $goodsclass_list = array_merge($goodsclass_list, $class_2_list);
  1331. $temp_3 = Db::name('goodsclass')->where(array(array('gc_parent_id', 'in', $class_2_ids)))->column('gc_id');
  1332. if (!empty($temp_3)) {
  1333. $class_3_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $temp_3)));
  1334. $goodsclass_list = array_merge($goodsclass_list, $class_3_list);
  1335. }
  1336. }
  1337. if (!empty($class_3_ids)) {
  1338. $class_3_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $class_3_ids)));
  1339. $goodsclass_list = array_merge($goodsclass_list, $class_3_list);
  1340. $temp_2 = Db::name('goodsclass')->where(array(array('gc_id', 'in', $class_3_ids)))->column('gc_parent_id');
  1341. $class_2_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $temp_2)));
  1342. $goodsclass_list = array_merge($goodsclass_list, $class_2_list);
  1343. $temp_1 = Db::name('goodsclass')->where(array(array('gc_id', 'in', $temp_2)))->column('gc_parent_id');
  1344. $class_1_list = model('goodsclass')->getGoodsclassList(array(array('gc_id', 'in', $temp_1)));
  1345. $goodsclass_list = array_merge($goodsclass_list, $class_1_list);
  1346. }
  1347. if (!empty($goodsclass_list)) {
  1348. $tree = new \mall\Tree();
  1349. $tree->setTree($goodsclass_list, 'gc_id', 'gc_parent_id', 'gc_name');
  1350. $result['class_list'] = $tree->getArrayList();
  1351. $store_bind_class_list = $result['class_list'];
  1352. }
  1353. }
  1354. }
  1355. ds_json_encode(10000, '', array('goods_class' => $store_bind_class_list, 'bind_all' => $bind_all));
  1356. }
  1357. }