Sellergoods.php 78 KB

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