Sellergoods.php 77 KB

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