Sellergoods.php 70 KB

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