Sellergoodsonline.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Sellergoodsonline extends BaseSeller
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergoodsadd.lang.php');
  19. $this->template_dir = 'default/seller/sellergoodsadd/';
  20. }
  21. public function index()
  22. {
  23. $this->goods_list();
  24. }
  25. /**
  26. * 出售中的商品列表
  27. */
  28. public function goods_list()
  29. {
  30. $goods_model = model('goods');
  31. $where = array();
  32. $where[] = array('goodscommon.store_id', '=', session('store_id'));
  33. $where[] = array('goodscommon.goods_state', '=', 1);
  34. $where[] = array('goodscommon.goods_verify', '=', 1);
  35. $storegc_id = intval(input('get.storegc_id'));
  36. if ($storegc_id > 0) {
  37. $where[] = array('goodscommon.goods_stcids', 'like', '%,' . $storegc_id . ',%');
  38. }
  39. $keyword = trim(input('get.keyword'));
  40. $search_type = trim(input('get.search_type'));
  41. if (trim($keyword) != '') {
  42. switch ($search_type) {
  43. case 0:
  44. $where[] = array('goodscommon.goods_name', 'like', '%' . trim($keyword) . '%');
  45. break;
  46. case 1:
  47. $where[] = array('goodscommon.goods_serial', 'like', '%' . trim($keyword) . '%');
  48. break;
  49. case 2:
  50. $where[] = array('goodscommon.goods_commonid', '=', intval($keyword));
  51. break;
  52. }
  53. }
  54. $stock = trim(input('get.stock'));
  55. switch ($stock) {
  56. case 1:
  57. $where[] = array('goods.goods_storage', 'EXP', Db::raw('<=goods.goods_storage_alarm'));
  58. $where[] = array('goods.goods_storage_alarm', '>', 0);
  59. break;
  60. }
  61. $goods_list = $goods_model->getGoodsUnionList($where, 'goods.goods_id,goods.goods_storage_alarm,goods.goods_storage,goodscommon.goods_commonid,goodscommon.mobile_body,goodscommon.goods_name,goodscommon.goods_addtime,goodscommon.goods_lock,goodscommon.goods_sort,goodscommon.goods_commend,goodscommon.goods_serial,goodscommon.is_virtual,goodscommon.virtual_type,goodscommon.is_goodsfcode,goodscommon.is_appoint,goodscommon.goods_advword,goodscommon.goods_image,goodscommon.store_id,goods.goods_promotion_price,goodscommon.goods_price', 'goodscommon.goods_commonid desc', 'goodscommon.goods_commonid', 10);
  62. foreach ($goods_list as $key => $val) {
  63. if ($val['goods_storage_alarm'] != 0 && $val['goods_storage'] <= $val['goods_storage_alarm']) {
  64. $goods_list[$key]['alarm'] = true;
  65. }
  66. $goods_list[$key]['sum'] = Db::name('goods')->where(array(array('goods_commonid', '=', $val['goods_commonid'])))->sum('goods_storage');
  67. $val['goods_type'] = 1;
  68. if ($val['goods_lock']) {
  69. $goods_info = $goods_model->getGoodsInfoAndPromotionById($val['goods_id']);
  70. if (isset($goods_info['groupbuy_info']) && $goods_info['groupbuy_info']) {
  71. $val['goods_type'] = 2;
  72. }
  73. if (isset($goods_info['pintuan_info']) && $goods_info['pintuan_info']) {
  74. $val['goods_type'] = 6;
  75. }
  76. if (isset($goods_info['bargain_info']) && $goods_info['bargain_info']) {
  77. $val['goods_type'] = 8;
  78. }
  79. if (isset($goods_info['presell_info']) && $goods_info['presell_info']) {
  80. $val['goods_type'] = 10;
  81. }
  82. if (isset($goods_info['xianshi_info']) && $goods_info['xianshi_info']) {
  83. $val['goods_type'] = 3;
  84. }
  85. if (isset($goods_info['wholesale_info']) && $goods_info['wholesale_info']) {
  86. $val['goods_type'] = 9;
  87. }
  88. }
  89. $goods_list[$key]['goods_type_cn'] = get_order_goodstype($val['goods_type']);
  90. }
  91. View::assign('show_page', $goods_model->page_info->render());
  92. View::assign('goods_list', $goods_list);
  93. // 商品分类
  94. $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => session('store_id'), 'storegc_state' => '1'));
  95. View::assign('store_goods_class', $store_goods_class);
  96. /* 设置卖家当前菜单 */
  97. $this->setSellerCurMenu('sellergoodsonline');
  98. $this->setSellerCurItem('goods_list');
  99. echo View::fetch($this->template_dir . 'store_goods_list_online');
  100. exit;
  101. }
  102. /**
  103. * 编辑商品页面
  104. */
  105. public function edit_goods()
  106. {
  107. $common_id = intval(input('param.commonid'));
  108. if ($common_id <= 0) {
  109. $this->error(lang('param_error'));
  110. }
  111. $goods_model = model('goods');
  112. $goodscommon_info = $goods_model->getGoodsCommonInfoByID($common_id);
  113. if (empty($goodscommon_info) || $goodscommon_info['store_id'] != session('store_id') || $goodscommon_info['goods_lock'] == 1) {
  114. $this->error(lang('goods_not_exist_or_lock'));
  115. }
  116. $where = array('goods_commonid' => $common_id, 'store_id' => session('store_id'));
  117. $goodscommon_info['g_storage'] = $goods_model->getGoodsSum($where, 'goods_storage');
  118. $goodscommon_info['spec_name'] = unserialize($goodscommon_info['spec_name']);
  119. if ($goodscommon_info['mobile_body'] != '') {
  120. $goodscommon_info['mb_body'] = unserialize($goodscommon_info['mobile_body']);
  121. if (is_array($goodscommon_info['mb_body'])) {
  122. $mobile_body = '[';
  123. foreach ($goodscommon_info['mb_body'] as $val) {
  124. $mobile_body .= '{"type":"' . $val['type'] . '","value":"' . $val['value'] . '"},';
  125. }
  126. $mobile_body = rtrim($mobile_body, ',') . ']';
  127. }
  128. $goodscommon_info['mobile_body'] = $mobile_body;
  129. }
  130. $class_id = intval(input('param.class_id'));
  131. if ($class_id > 0) {
  132. $goodscommon_info['gc_id'] = $class_id;
  133. }
  134. $goods_class = model('goodsclass')->getGoodsclassLineForTag($goodscommon_info['gc_id']);
  135. View::assign('goods_class', $goods_class);
  136. $type_model = model('type');
  137. // 获取类型相关数据
  138. $typeinfo = $type_model->getAttribute($goods_class['type_id'], session('store_id'), $goodscommon_info['gc_id']);
  139. list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
  140. View::assign('spec_json', $spec_json);
  141. View::assign('sign_i', count($spec_list));
  142. View::assign('spec_list', $spec_list);
  143. View::assign('attr_list', $attr_list);
  144. View::assign('brand_list', $brand_list);
  145. // 取得商品规格的输入值
  146. $goods_array = $goods_model->getGoodsList($where, 'goods_id,goods_marketprice,goods_price,goods_storage,goods_serial,goods_storage_alarm,goods_spec,goods_weight,virtual_content');
  147. $sp_value = array();
  148. if (is_array($goods_array) && !empty($goods_array)) {
  149. $goodscommon_info['goods_weight'] = $goods_array[0]['goods_weight'];
  150. switch ($goodscommon_info['virtual_type']) {
  151. case 1:
  152. $goodscommon_info['vc_card'] = $goods_array[0]['virtual_content'];
  153. break;
  154. case 2:
  155. $goodscommon_info['vc_pan'] = $goods_array[0]['virtual_content'];
  156. break;
  157. case 3:
  158. $goodscommon_info['vc_file'] = $goods_array[0]['virtual_content'];
  159. break;
  160. }
  161. // 取得已选择了哪些商品的属性
  162. $attr_checked_l = $type_model->typeRelatedList('goodsattrindex', array(
  163. 'goods_id' => intval($goods_array[0]['goods_id'])
  164. ), 'attrvalue_id');
  165. $attr_checked = array();
  166. if (is_array($attr_checked_l) && !empty($attr_checked_l)) {
  167. foreach ($attr_checked_l as $val) {
  168. $attr_checked[] = $val['attrvalue_id'];
  169. }
  170. }
  171. View::assign('attr_checked', $attr_checked);
  172. $spec_checked = array();
  173. foreach ($goods_array as $k => $v) {
  174. $a = unserialize($v['goods_spec']);
  175. if (!empty($a)) {
  176. foreach ($a as $key => $val) {
  177. $spec_checked[$key]['id'] = $key;
  178. $spec_checked[$key]['name'] = addslashes($val);
  179. }
  180. $matchs = array_keys($a);
  181. sort($matchs);
  182. $id = str_replace(',', '', implode(',', $matchs));
  183. $sp_value['i_' . $id . '|marketprice'] = $v['goods_marketprice'];
  184. $sp_value['i_' . $id . '|price'] = $v['goods_price'];
  185. $sp_value['i_' . $id . '|id'] = $v['goods_id'];
  186. $sp_value['i_' . $id . '|stock'] = $v['goods_storage'];
  187. $sp_value['i_' . $id . '|alarm'] = $v['goods_storage_alarm'];
  188. $sp_value['i_' . $id . '|sku'] = $v['goods_serial'];
  189. $sp_value['i_' . $id . '|goods_weight'] = $v['goods_weight'];
  190. switch ($goodscommon_info['virtual_type']) {
  191. case 1:
  192. $sp_value['i_' . $id . '|vc_card'] = $v['virtual_content'];
  193. break;
  194. case 2:
  195. $sp_value['i_' . $id . '|vc_pan'] = $v['virtual_content'];
  196. break;
  197. case 3:
  198. $sp_value['i_' . $id . '|vc_file'] = $v['virtual_content'];
  199. break;
  200. }
  201. }
  202. }
  203. View::assign('spec_checked', $spec_checked);
  204. }
  205. $goodscommon_info['store_service_ids'] = explode(',', $goodscommon_info['store_service_ids']);
  206. View::assign('goods', $goodscommon_info);
  207. View::assign('sp_value', $sp_value);
  208. // 实例化店铺商品分类模型
  209. $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => session('store_id'), 'storegc_state' => '1'));
  210. View::assign('store_goods_class', $store_goods_class);
  211. //处理商品所属分类
  212. $store_goods_class_tmp = array();
  213. if (!empty($store_goods_class)) {
  214. foreach ($store_goods_class as $k => $v) {
  215. $store_goods_class_tmp[$v['storegc_id']] = $v;
  216. if (isset($v['child'])) {
  217. foreach ($v['child'] as $son_k => $son_v) {
  218. $store_goods_class_tmp[$son_v['storegc_id']] = $son_v;
  219. }
  220. }
  221. }
  222. }
  223. $goodscommon_info['goods_stcids'] = trim($goodscommon_info['goods_stcids'], ',');
  224. $goods_stcids = empty($goodscommon_info['goods_stcids']) ? array() : explode(',', $goodscommon_info['goods_stcids']);
  225. $goods_stcids_tmp = $goods_stcids_new = array();
  226. if (!empty($goods_stcids)) {
  227. foreach ($goods_stcids as $k => $v) {
  228. if (isset($store_goods_class_tmp[$v])) {
  229. $storegc_parent_id = $store_goods_class_tmp[$v]['storegc_parent_id'];
  230. } else {
  231. $storegc_parent_id = 0;
  232. }
  233. //分类进行分组,构造为array('1'=>array(5,6,8));
  234. if ($storegc_parent_id > 0) { //如果为二级分类,则分组到父级分类下
  235. $goods_stcids_tmp[$storegc_parent_id][] = $v;
  236. } elseif (empty($goods_stcids_tmp[$v])) { //如果为一级分类而且分组不存在,则建立一个空分组数组
  237. $goods_stcids_tmp[$v] = array();
  238. }
  239. }
  240. foreach ($goods_stcids_tmp as $k => $v) {
  241. if (!empty($v) && count($v) > 0) {
  242. $goods_stcids_new = array_merge($goods_stcids_new, $v);
  243. } else {
  244. $goods_stcids_new[] = $k;
  245. }
  246. }
  247. }
  248. View::assign('store_class_goods', $goods_stcids_new);
  249. // 小时分钟显示
  250. $hour_array = array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23');
  251. View::assign('hour_array', $hour_array);
  252. $minute_array = array('05', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55');
  253. View::assign('minute_array', $minute_array);
  254. // 关联版式
  255. $plate_list = model('storeplate')->getStoreplateList(array('store_id' => session('store_id')), 'storeplate_id,storeplate_name,storeplate_position');
  256. $plate_list = array_under_reset($plate_list, 'storeplate_position', 2);
  257. View::assign('plate_list', $plate_list);
  258. // F码
  259. if ($goodscommon_info['is_goodsfcode'] == 1) {
  260. $fcode_array = model('goodsfcode')->getGoodsfcodeList(array('goods_commonid' => $goodscommon_info['goods_commonid']));
  261. View::assign('fcode_array', $fcode_array);
  262. }
  263. View::assign('edit_goods_sign', true);
  264. $store_service_model = model('store_service');
  265. $store_service_list = $store_service_model->getStoreServiceList(array(array('store_id', '=', session('store_id'))), '*', 0);
  266. View::assign('store_service_list', $store_service_list);
  267. /* 设置卖家当前菜单 */
  268. $this->setSellerCurMenu('sellergoodsonline');
  269. $this->setSellerCurItem('edit_goods');
  270. return View::fetch($this->template_dir . 'store_goods_add_step2');
  271. }
  272. /**
  273. * 编辑商品保存
  274. */
  275. public function edit_save_goods()
  276. {
  277. $common_id = intval(input('param.commonid'));
  278. if (!request()->isPost() || $common_id <= 0) {
  279. ds_json_encode(10001, lang('store_goods_index_goods_edit_fail'));
  280. }
  281. $gc_id = intval(input('post.cate_id'));
  282. // 验证商品分类是否存在且商品分类是否为最后一级
  283. $data = model('goodsclass')->getGoodsclassForCacheModel();
  284. if (!isset($data[$gc_id]) || isset($data[$gc_id]['child']) || isset($data[$gc_id]['childchild'])) {
  285. ds_json_encode(10001, lang('store_goods_index_again_choose_category1'));
  286. }
  287. // 三方店铺验证是否绑定了该分类
  288. if (!check_platform_store()) {
  289. //商品分类 提供批量显示所有分类插件
  290. $storebindclass_model = model('storebindclass');
  291. $goods_class = model('goodsclass')->getGoodsclassForCacheModel();
  292. $condition = array();
  293. $condition[] = array('store_id', '=', session('store_id'));
  294. $class_2 = isset($goods_class[$gc_id]['gc_parent_id']) ? $goods_class[$gc_id]['gc_parent_id'] : 0;
  295. $class_1 = isset($goods_class[$class_2]['gc_parent_id']) ? $goods_class[$class_2]['gc_parent_id'] : 0;
  296. $condition_class_1 = array(array('class_1', '=', ($class_1 > 0) ? $class_1 : (($class_2 > 0) ? $class_2 : $gc_id)));
  297. $condition_class_2 = array(array('class_2', '=', ($class_1 > 0) ? $class_2 : (($class_2 > 0) ? $gc_id : 0)));
  298. $condition_class_3 = array(array('class_3', '=', ($class_1 > 0 && $class_2 > 0) ? $gc_id : 0));
  299. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  300. if (empty($bind_info)) {
  301. $condition_class_3 = array(array('class_3', '=', 0));
  302. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  303. if (empty($bind_info)) {
  304. $condition_class_2 = array(array('class_2', '=', 0));
  305. $condition_class_3 = array(array('class_3', '=', 0));
  306. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  307. if (empty($bind_info)) {
  308. $condition_class_1 = array(array('class_1', '=', 0));
  309. $condition_class_2 = array(array('class_2', '=', 0));
  310. $condition_class_3 = array(array('class_3', '=', 0));
  311. $bind_info = $storebindclass_model->getStorebindclassInfo(array_merge($condition, $condition_class_1, $condition_class_2, $condition_class_3));
  312. if (empty($bind_info)) {
  313. ds_json_encode(10001, lang('store_goods_index_again_choose_category2'));
  314. }
  315. }
  316. }
  317. }
  318. }
  319. // 分类信息
  320. $goods_class = model('goodsclass')->getGoodsclassLineForTag(intval(input('post.cate_id')));
  321. $goods_model = model('goods');
  322. $update_common = array();
  323. $update_common['goods_name'] = input('post.g_name');
  324. $update_common['goods_advword'] = input('post.g_jingle');
  325. $update_common['gc_id'] = $gc_id;
  326. $update_common['gc_id_1'] = isset($goods_class['gc_id_1']) ? intval($goods_class['gc_id_1']) : 0;
  327. $update_common['gc_id_2'] = isset($goods_class['gc_id_2']) ? intval($goods_class['gc_id_2']) : 0;
  328. $update_common['gc_id_3'] = isset($goods_class['gc_id_3']) ? intval($goods_class['gc_id_3']) : 0;
  329. $update_common['gc_name'] = input('post.cate_name');
  330. $update_common['brand_id'] = input('post.b_id');
  331. $update_common['brand_name'] = input('post.b_name');
  332. $update_common['type_id'] = intval(input('post.type_id'));
  333. $update_common['goods_image'] = input('post.image_path');
  334. $update_common['goodsvideo_name'] = input('post.goodsvideo_name');
  335. $update_common['goods_price'] = floatval(input('post.g_price'));
  336. $update_common['goods_marketprice'] = floatval(input('post.g_marketprice'));
  337. $update_common['goods_costprice'] = floatval(input('post.g_costprice'));
  338. $update_common['goods_discount'] = floatval(input('post.g_discount'));
  339. $update_common['goods_serial'] = input('post.g_serial');
  340. $update_common['goods_storage_alarm'] = intval(input('post.g_alarm'));
  341. $update_common['goods_attr'] = !empty(input('post.attr/a')) ? serialize(input('post.attr/a')) : '';
  342. $update_common['store_service_ids'] = !empty(input('post.store_service_ids/a')) ? implode(',', input('post.store_service_ids/a')) : '';
  343. $goods_body = preg_replace_callback("/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i", function ($matches) {
  344. return str_replace($matches[2], strip_tags($matches[2]), $matches[0]);
  345. }, htmlspecialchars_decode(input('post.goods_body')));
  346. $update_common['goods_body'] = $goods_body;
  347. // 序列化保存手机端商品描述数据
  348. $mobile_body = input('post.m_body');
  349. if ($mobile_body != '') {
  350. $mobile_body = str_replace('&quot;', '"', $mobile_body);
  351. $mobile_body = json_decode($mobile_body, true);
  352. if (!empty($mobile_body)) {
  353. $mobile_body = serialize($mobile_body);
  354. } else {
  355. $mobile_body = '';
  356. }
  357. }
  358. $update_common['mobile_body'] = $mobile_body;
  359. $update_common['goods_commend'] = intval(input('post.g_commend'));
  360. $update_common['goods_state'] = ($this->store_info['store_state'] != 1) ? 0 : intval(input('post.g_state')); // 店铺关闭时,商品下架
  361. $update_common['goods_shelftime'] = strtotime(input('post.starttime')) + intval(input('post.starttime_H')) * 3600 + intval(input('post.starttime_i')) * 60;
  362. $update_common['goods_verify'] = (config('ds_config.goods_verify') == 1) ? 10 : 1;
  363. $update_common['spec_name'] = !empty(input('post.spec/a')) ? serialize(input('post.sp_name/a')) : serialize(null);
  364. $update_common['spec_value'] = !empty(input('post.spec/a')) ? serialize(input('post.sp_val/a')) : serialize(null);
  365. $update_common['goods_vat'] = intval(input('post.g_vat'));
  366. $update_common['areaid_1'] = intval(input('post.province_id'));
  367. $update_common['areaid_2'] = intval(input('post.city_id'));
  368. $update_common['transport_id'] = (input('post.freight') == '0') ? '0' : intval(input('post.transport_id')); // 售卖区域
  369. $update_common['transport_title'] = input('post.transport_title');
  370. $update_common['goods_freight'] = floatval(input('post.g_freight'));
  371. $sellergoodsonline_validate = ds_validate('sellergoodsonline');
  372. if (!$sellergoodsonline_validate->scene('edit_save_goods')->check($update_common)) {
  373. ds_json_encode('10001', $sellergoodsonline_validate->getError());
  374. }
  375. //查询店铺商品分类
  376. $goods_stcids_arr = array();
  377. $sgcate_id_array = input('post.sgcate_id/a'); #获取数组
  378. if (!empty($sgcate_id_array)) {
  379. $sgcate_id_arr = array();
  380. foreach ($sgcate_id_array as $k => $v) {
  381. $sgcate_id_arr[] = intval($v);
  382. }
  383. $sgcate_id_arr = array_unique($sgcate_id_arr);
  384. $store_goods_class = model('storegoodsclass')->getStoregoodsclassList(array(array('store_id', '=', session('store_id')), array('storegc_id', 'in', $sgcate_id_arr), array('storegc_state', '=', '1')));
  385. if (!empty($store_goods_class)) {
  386. foreach ($store_goods_class as $k => $v) {
  387. if ($v['storegc_id'] > 0) {
  388. $goods_stcids_arr[] = $v['storegc_id'];
  389. }
  390. if ($v['storegc_parent_id'] > 0) {
  391. $goods_stcids_arr[] = $v['storegc_parent_id'];
  392. }
  393. }
  394. $goods_stcids_arr = array_unique($goods_stcids_arr);
  395. sort($goods_stcids_arr);
  396. }
  397. }
  398. if (empty($goods_stcids_arr)) {
  399. $update_common['goods_stcids'] = '';
  400. } else {
  401. $update_common['goods_stcids'] = ',' . implode(',', $goods_stcids_arr) . ',';
  402. }
  403. $update_common['plateid_top'] = intval(input('post.plate_top')) > 0 ? intval(input('post.plate_top')) : '';
  404. $update_common['plateid_bottom'] = intval(input('post.plate_bottom')) > 0 ? intval(input('post.plate_bottom')) : '';
  405. $update_common['is_virtual'] = intval(input('post.is_gv'));
  406. $update_common['virtual_type'] = $update_common['is_virtual'] ? intval(input('post.virtual_type')) : 0;
  407. $update_common['virtual_indate'] = input('post.g_vindate') != '' ? (strtotime(input('post.g_vindate')) + 24 * 60 * 60 - 1) : 0; // 当天的最后一秒结束
  408. $update_common['virtual_limit'] = intval(input('post.g_vlimit')) > 10 || intval(input('post.g_vlimit')) < 0 ? 10 : intval(input('post.g_vlimit'));
  409. $update_common['virtual_invalid_refund'] = intval(input('post.g_vinvalidrefund'));
  410. $update_common['is_goodsfcode'] = $update_common['is_virtual'] ? 0 : intval(input('post.is_fc'));
  411. $update_common['is_appoint'] = $update_common['is_virtual'] ? 0 : intval(input('post.is_appoint')); // 只有库存为零的商品可以预约
  412. $update_common['appoint_satedate'] = $update_common['is_appoint'] == 1 ? strtotime(input('post.g_saledate')) : ''; // 预约商品的销售时间
  413. $update_common['is_platform_store'] = in_array(session('store_id'), model('store')->getOwnShopIds()) ? 1 : 0;
  414. // 开始事务
  415. Db::startTrans();
  416. try {
  417. $goods_model->lock = true;
  418. $goodsgift_model = model('goodsgift');
  419. // 清除原有规格数据
  420. $type_model = model('type');
  421. $type_model->delGoodsAttr(array('goods_commonid' => $common_id));
  422. // 更新商品规格
  423. $goodsid_array = array();
  424. $colorid_array = array();
  425. $spec_array = input('post.spec/a'); #获取数组
  426. if (is_array($spec_array) && !empty($spec_array)) {
  427. foreach ($spec_array as $value) {
  428. $goods_info = $goods_model->getGoodsInfo(array('goods_id' => $value['goods_id'], 'goods_commonid' => $common_id, 'store_id' => session('store_id')), 'goods_id');
  429. if (!empty($goods_info)) {
  430. $goods_id = $goods_info['goods_id'];
  431. $update = array();
  432. $update['goods_commonid'] = $common_id;
  433. $update['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']);
  434. $update['goods_advword'] = $update_common['goods_advword'];
  435. $update['store_id'] = session('store_id');
  436. $update['store_name'] = session('store_name');
  437. $update['gc_id'] = $update_common['gc_id'];
  438. $update['gc_id_1'] = $update_common['gc_id_1'];
  439. $update['gc_id_2'] = $update_common['gc_id_2'];
  440. $update['gc_id_3'] = $update_common['gc_id_3'];
  441. $update['brand_id'] = $update_common['brand_id'];
  442. $update['goods_price'] = $value['price'];
  443. $update['goods_marketprice'] = $value['marketprice'] == 0 ? $update_common['goods_marketprice'] : $value['marketprice'];
  444. $update['goods_serial'] = $value['sku'];
  445. $update['goods_storage_alarm'] = intval($value['alarm']);
  446. $update['goods_spec'] = serialize($value['sp_value']);
  447. $update['goods_storage'] = $value['stock'];
  448. $update['goods_weight'] = $value['goods_weight'];
  449. $update['goods_state'] = $update_common['goods_state'];
  450. $update['goods_verify'] = $update_common['goods_verify'];
  451. $update['goods_edittime'] = TIMESTAMP;
  452. $update['areaid_1'] = $update_common['areaid_1'];
  453. $update['areaid_2'] = $update_common['areaid_2'];
  454. $update['color_id'] = isset($value['color']) ? intval($value['color']) : '';
  455. $update['transport_id'] = $update_common['transport_id'];
  456. $update['goods_freight'] = $update_common['goods_freight'];
  457. $update['goods_vat'] = $update_common['goods_vat'];
  458. $update['goods_commend'] = $update_common['goods_commend'];
  459. $update['goods_stcids'] = $update_common['goods_stcids'];
  460. $update['is_virtual'] = $update_common['is_virtual'];
  461. $update['virtual_indate'] = $update_common['virtual_indate'];
  462. $update['virtual_limit'] = $update_common['virtual_limit'];
  463. $update['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  464. $update['is_goodsfcode'] = $update_common['is_goodsfcode'];
  465. $update['is_appoint'] = $update_common['is_appoint'];
  466. switch ($update_common['virtual_type']) {
  467. case 1:
  468. $update['virtual_content'] = $value['vc_card'];
  469. $res = $goods_model->getAvailableGoodsCard(array_merge($update, array('goods_id' => $goods_info['goods_id'])));
  470. if ($res['code']) {
  471. $update['goods_storage'] = $res['data']['card_num'];
  472. } else {
  473. $update['goods_storage'] = 0;
  474. }
  475. break;
  476. case 2:
  477. $update['virtual_content'] = $value['vc_pan'];
  478. $update['goods_storage'] = 1;
  479. break;
  480. case 3:
  481. $update['virtual_content'] = $value['vc_file'];
  482. $update['goods_storage'] = 1;
  483. break;
  484. default:
  485. $update['virtual_content'] = '';
  486. }
  487. // 虚拟商品不能有赠品
  488. if ($update_common['is_virtual'] == 1) {
  489. $update['is_have_gift'] = 0;
  490. $goodsgift_model->delGoodsgift(array('goods_id' => $goods_id));
  491. }
  492. $update['is_platform_store'] = $update_common['is_platform_store'];
  493. $goods_model->editGoodsById($update, $goods_id);
  494. } else {
  495. $insert = array();
  496. $insert['goods_commonid'] = $common_id;
  497. $insert['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']);
  498. $insert['goods_advword'] = $update_common['goods_advword'];
  499. $insert['store_id'] = session('store_id');
  500. $insert['store_name'] = session('store_name');
  501. $insert['gc_id'] = $update_common['gc_id'];
  502. $insert['gc_id_1'] = $update_common['gc_id_1'];
  503. $insert['gc_id_2'] = $update_common['gc_id_2'];
  504. $insert['gc_id_3'] = $update_common['gc_id_3'];
  505. $insert['brand_id'] = $update_common['brand_id'];
  506. $insert['goods_price'] = $value['price'];
  507. $insert['goods_promotion_price'] = $value['price'];
  508. $insert['goods_marketprice'] = $value['marketprice'] == 0 ? $update_common['goods_marketprice'] : $value['marketprice'];
  509. $insert['goods_serial'] = $value['sku'];
  510. $insert['goods_storage_alarm'] = intval($value['alarm']);
  511. $insert['goods_spec'] = serialize($value['sp_value']);
  512. $insert['goods_storage'] = $value['stock'];
  513. $insert['goods_weight'] = $value['goods_weight'];
  514. $insert['goods_image'] = $update_common['goods_image'];
  515. $insert['goods_state'] = $update_common['goods_state'];
  516. $insert['goods_verify'] = $update_common['goods_verify'];
  517. $insert['goods_addtime'] = TIMESTAMP;
  518. $insert['goods_edittime'] = TIMESTAMP;
  519. $insert['areaid_1'] = $update_common['areaid_1'];
  520. $insert['areaid_2'] = $update_common['areaid_2'];
  521. $insert['color_id'] = isset($value['color']) ? intval($value['color']) : '';
  522. $insert['transport_id'] = $update_common['transport_id'];
  523. $insert['goods_freight'] = $update_common['goods_freight'];
  524. $insert['goods_vat'] = $update_common['goods_vat'];
  525. $insert['goods_commend'] = $update_common['goods_commend'];
  526. $insert['goods_stcids'] = $update_common['goods_stcids'];
  527. $insert['is_virtual'] = $update_common['is_virtual'];
  528. $insert['virtual_indate'] = $update_common['virtual_indate'];
  529. $insert['virtual_limit'] = $update_common['virtual_limit'];
  530. $insert['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  531. $insert['is_goodsfcode'] = $update_common['is_goodsfcode'];
  532. $insert['is_appoint'] = $update_common['is_appoint'];
  533. $insert['is_platform_store'] = $update_common['is_platform_store'];
  534. switch ($update_common['virtual_type']) {
  535. case 1:
  536. $insert['virtual_content'] = $value['vc_card'];
  537. $card_list = explode("\r\n", $insert['virtual_content']);
  538. $insert['goods_storage'] = count($card_list);
  539. break;
  540. case 2:
  541. $insert['virtual_content'] = $value['vc_pan'];
  542. $insert['goods_storage'] = 1;
  543. break;
  544. case 3:
  545. $insert['virtual_content'] = $value['vc_file'];
  546. $insert['goods_storage'] = 1;
  547. break;
  548. default:
  549. $insert['virtual_content'] = '';
  550. }
  551. $goods_id = $goods_model->addGoods($insert);
  552. }
  553. $goodsid_array[] = intval($goods_id);
  554. $colorid_array[] = isset($value['color']) ? intval($value['color']) : '';
  555. $type_model->addGoodsType($goods_id, $common_id, array('cate_id' => input('post.cate_id'), 'type_id' => input('post.type_id'), 'attr' => input('post.attr/a')));
  556. }
  557. } else {
  558. $goods_info = $goods_model->getGoodsInfo(array('goods_spec' => serialize(null), 'goods_commonid' => $common_id, 'store_id' => session('store_id')), 'goods_id');
  559. if (!empty($goods_info)) {
  560. $goods_id = $goods_info['goods_id'];
  561. $update = array();
  562. $update['goods_commonid'] = $common_id;
  563. $update['goods_name'] = $update_common['goods_name'];
  564. $update['goods_advword'] = $update_common['goods_advword'];
  565. $update['store_id'] = session('store_id');
  566. $update['store_name'] = session('store_name');
  567. $update['gc_id'] = $update_common['gc_id'];
  568. $update['gc_id_1'] = $update_common['gc_id_1'];
  569. $update['gc_id_2'] = $update_common['gc_id_2'];
  570. $update['gc_id_3'] = $update_common['gc_id_3'];
  571. $update['brand_id'] = $update_common['brand_id'];
  572. $update['goods_price'] = $update_common['goods_price'];
  573. $update['goods_marketprice'] = $update_common['goods_marketprice'];
  574. $update['goods_serial'] = $update_common['goods_serial'];
  575. $update['goods_storage_alarm'] = $update_common['goods_storage_alarm'];
  576. $update['goods_spec'] = serialize(null);
  577. $update['goods_storage'] = intval(input('post.g_storage'));
  578. $update['goods_weight'] = floatval(input('post.goods_weight'));
  579. $update['goods_state'] = $update_common['goods_state'];
  580. $update['goods_verify'] = $update_common['goods_verify'];
  581. $update['goods_edittime'] = TIMESTAMP;
  582. $update['areaid_1'] = $update_common['areaid_1'];
  583. $update['areaid_2'] = $update_common['areaid_2'];
  584. $update['color_id'] = 0;
  585. $update['transport_id'] = $update_common['transport_id'];
  586. $update['goods_freight'] = $update_common['goods_freight'];
  587. $update['goods_vat'] = $update_common['goods_vat'];
  588. $update['goods_commend'] = $update_common['goods_commend'];
  589. $update['goods_stcids'] = $update_common['goods_stcids'];
  590. $update['is_virtual'] = $update_common['is_virtual'];
  591. $update['virtual_indate'] = $update_common['virtual_indate'];
  592. $update['virtual_limit'] = $update_common['virtual_limit'];
  593. $update['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  594. $update['is_goodsfcode'] = $update_common['is_goodsfcode'];
  595. $update['is_appoint'] = $update_common['is_appoint'];
  596. switch ($update_common['virtual_type']) {
  597. case 1:
  598. $update['virtual_content'] = input('post.vc_card');
  599. $res = $goods_model->getAvailableGoodsCard(array_merge($update, array('goods_id' => $goods_info['goods_id'])));
  600. if ($res['code']) {
  601. $update['goods_storage'] = $res['data']['card_num'];
  602. } else {
  603. $update['goods_storage'] = 0;
  604. }
  605. break;
  606. case 2:
  607. $update['virtual_content'] = input('post.vc_pan');
  608. $update['goods_storage'] = 1;
  609. break;
  610. case 3:
  611. $update['virtual_content'] = input('post.vc_file');
  612. $update['goods_storage'] = 1;
  613. break;
  614. default:
  615. $update['virtual_content'] = '';
  616. }
  617. if ($update_common['is_virtual'] == 1) {
  618. $update['is_have_gift'] = 0;
  619. $goodsgift_model->delGoodsgift(array('goods_id' => $goods_id));
  620. }
  621. $update['is_platform_store'] = $update_common['is_platform_store'];
  622. $goods_model->editGoodsById($update, $goods_id);
  623. } else {
  624. $insert = array();
  625. $insert['goods_commonid'] = $common_id;
  626. $insert['goods_name'] = $update_common['goods_name'];
  627. $insert['goods_advword'] = $update_common['goods_advword'];
  628. $insert['store_id'] = session('store_id');
  629. $insert['store_name'] = session('store_name');
  630. $insert['gc_id'] = $update_common['gc_id'];
  631. $insert['gc_id_1'] = $update_common['gc_id_1'];
  632. $insert['gc_id_2'] = $update_common['gc_id_2'];
  633. $insert['gc_id_3'] = $update_common['gc_id_3'];
  634. $insert['brand_id'] = $update_common['brand_id'];
  635. $insert['goods_price'] = $update_common['goods_price'];
  636. $insert['goods_promotion_price'] = $update_common['goods_price'];
  637. $insert['goods_marketprice'] = $update_common['goods_marketprice'];
  638. $insert['goods_serial'] = $update_common['goods_serial'];
  639. $insert['goods_storage_alarm'] = $update_common['goods_storage_alarm'];
  640. $insert['goods_spec'] = serialize(null);
  641. $insert['goods_storage'] = intval(input('post.g_storage'));
  642. $insert['goods_weight'] = floatval(input('post.goods_weight'));
  643. $insert['goods_image'] = $update_common['goods_image'];
  644. $insert['goods_state'] = $update_common['goods_state'];
  645. $insert['goods_verify'] = $update_common['goods_verify'];
  646. $insert['goods_addtime'] = TIMESTAMP;
  647. $insert['goods_edittime'] = TIMESTAMP;
  648. $insert['areaid_1'] = $update_common['areaid_1'];
  649. $insert['areaid_2'] = $update_common['areaid_2'];
  650. $insert['color_id'] = 0;
  651. $insert['transport_id'] = $update_common['transport_id'];
  652. $insert['goods_freight'] = $update_common['goods_freight'];
  653. $insert['goods_vat'] = $update_common['goods_vat'];
  654. $insert['goods_commend'] = $update_common['goods_commend'];
  655. $insert['goods_stcids'] = $update_common['goods_stcids'];
  656. $insert['is_virtual'] = $update_common['is_virtual'];
  657. $insert['virtual_indate'] = $update_common['virtual_indate'];
  658. $insert['virtual_limit'] = $update_common['virtual_limit'];
  659. $insert['virtual_invalid_refund'] = $update_common['virtual_invalid_refund'];
  660. $insert['is_goodsfcode'] = $update_common['is_goodsfcode'];
  661. $insert['is_appoint'] = $update_common['is_appoint'];
  662. $insert['is_platform_store'] = $update_common['is_platform_store'];
  663. switch ($update_common['virtual_type']) {
  664. case 1:
  665. $insert['virtual_content'] = input('post.vc_card');
  666. $card_list = explode("\r\n", $insert['virtual_content']);
  667. $insert['goods_storage'] = count($card_list);
  668. break;
  669. case 2:
  670. $insert['virtual_content'] = input('post.vc_pan');
  671. $insert['goods_storage'] = 1;
  672. break;
  673. case 3:
  674. $insert['virtual_content'] = input('post.vc_file');
  675. $insert['goods_storage'] = 1;
  676. break;
  677. default:
  678. $insert['virtual_content'] = '';
  679. }
  680. $goods_id = $goods_model->addGoods($insert);
  681. }
  682. $goodsid_array[] = intval($goods_id);
  683. $colorid_array[] = 0;
  684. $type_model->addGoodsType($goods_id, $common_id, array('cate_id' => input('post.cate_id'), 'type_id' => input('post.type_id'), 'attr' => input('post.attr/a')));
  685. }
  686. // 清理商品数据
  687. $condition_goods = array();
  688. $condition_goods[] = array('goods_id', 'not in', $goodsid_array);
  689. $condition_goods[] = array('goods_commonid', '=', $common_id);
  690. $condition_goods[] = array('store_id', '=', session('store_id'));
  691. $goods_model->delGoods($condition_goods);
  692. // 清理商品图片表
  693. $colorid_array = array_unique($colorid_array);
  694. $condition_goodsimages = array();
  695. $condition_goodsimages[] = array('goods_commonid', '=', $common_id);
  696. $condition_goodsimages[] = array('color_id', 'not in', $colorid_array);
  697. $goods_model->delGoodsImages($condition_goodsimages);
  698. // 更新商品默认主图
  699. $default_image_list = $goods_model->getGoodsImageList(array('goods_commonid' => $common_id, 'goodsimage_isdefault' => 1), 'color_id,goodsimage_url');
  700. if (!empty($default_image_list)) {
  701. foreach ($default_image_list as $val) {
  702. $goods_model->editGoods(array('goods_image' => $val['goodsimage_url']), array('goods_commonid' => $common_id, 'color_id' => $val['color_id']));
  703. }
  704. }
  705. // 商品加入上架队列
  706. if (!empty(input('post.starttime'))) {
  707. $selltime = strtotime(input('post.starttime')) + intval(input('post.starttime_H')) * 3600 + intval(input('post.starttime_i')) * 60;
  708. if ($selltime > TIMESTAMP) {
  709. $this->addcron(array('cron_exetime' => $selltime, 'cron_value' => serialize(intval($common_id)), 'cron_type' => 'editProducesOnline'), true);
  710. }
  711. }
  712. // 添加操作日志
  713. $this->recordSellerlog('编辑商品,平台货号:' . $common_id);
  714. if ($update_common['is_virtual'] == 1 || $update_common['is_goodsfcode'] == 1) {
  715. // 如果是特殊商品清理促销活动,抢购、秒杀、组合销售
  716. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'clearSpecialGoodsPromotion', 'cron_value' => serialize(array('goods_commonid' => $common_id, 'goodsid_array' => $goodsid_array))));
  717. } else {
  718. // 更新商品促销价格
  719. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'updateGoodsPromotionPriceByGoodsCommonId', 'cron_value' => serialize($common_id)));
  720. }
  721. // 生成F码
  722. if ($update_common['is_goodsfcode'] == 1) {
  723. model('goodsfcode')->createGoodsfcode(array('goods_commonid' => $common_id, 'goodsfcode_count' => intval(input('post.g_fccount')), 'goodsfcode_prefix' => input('post.g_fcprefix')));
  724. }
  725. $return = $goods_model->editGoodsCommon($update_common, array('goods_commonid' => $common_id, 'store_id' => session('store_id')));
  726. } catch (\Exception $e) {
  727. Db::rollback();
  728. ds_json_encode(10001, $e->getMessage());
  729. }
  730. Db::commit();
  731. ds_json_encode(10000, lang('ds_common_op_succ'));
  732. }
  733. /**
  734. * 编辑图片
  735. */
  736. public function edit_image()
  737. {
  738. $common_id = intval(input('param.commonid'));
  739. if ($common_id <= 0) {
  740. $this->error(lang('param_error'), (string) url('Seller/index'));
  741. }
  742. $goods_model = model('goods');
  743. $common_list = $goods_model->getGoodsCommonInfoByID($common_id);
  744. if ($common_list['store_id'] != session('store_id') || $common_list['goods_lock'] == 1) {
  745. $this->error(lang('goods_not_exist_or_lock'), (string) url('Seller/index'));
  746. }
  747. $spec_value = unserialize($common_list['spec_value']);
  748. if (isset($spec_value[1])) {
  749. View::assign('spec_value', $spec_value);
  750. } else {
  751. View::assign('spec_value', null);
  752. }
  753. $image_list = $goods_model->getGoodsImageList(array('goods_commonid' => $common_id));
  754. $image_list = array_under_reset($image_list, 'color_id', 2);
  755. $img_array = $goods_model->getGoodsList(array('goods_commonid' => $common_id), '*', 'color_id');
  756. // 整理,更具id查询颜色名称
  757. if (!empty($img_array)) {
  758. foreach ($img_array as $val) {
  759. if (isset($image_list[$val['color_id']])) {
  760. $image_array[$val['color_id']] = $image_list[$val['color_id']];
  761. } else {
  762. $image_array[$val['color_id']][0]['goodsimage_url'] = isset($val['goodsimage_url']) ? $val['goodsimage_url'] : '';
  763. $image_array[$val['color_id']][0]['goodsimage_sort'] = 0;
  764. $image_array[$val['color_id']][0]['goodsimage_isdefault'] = 1;
  765. }
  766. $colorid_array[] = $val['color_id'];
  767. }
  768. }
  769. View::assign('img', $image_array);
  770. $spec_model = model('spec');
  771. $value_array = $spec_model->getSpecvalueList(array(array('spvalue_id', 'in', $colorid_array), array('store_id', '=', session('store_id'))), 'spvalue_id,spvalue_name');
  772. if (empty($value_array)) {
  773. $value_array[] = array('spvalue_id' => '0', 'spvalue_name' => lang('no_color'));
  774. }
  775. View::assign('value_array', $value_array);
  776. View::assign('commonid', $common_id);
  777. /* 设置卖家当前菜单 */
  778. $this->setSellerCurMenu('sellergoodsonline');
  779. $this->setSellerCurItem('edit_image');
  780. View::assign('edit_goods_sign', true);
  781. return View::fetch($this->template_dir . 'store_goods_add_step3');
  782. }
  783. /**
  784. * 保存商品图片
  785. */
  786. public function edit_save_image()
  787. {
  788. if (request()->isPost()) {
  789. $common_id = intval(input('param.commonid'));
  790. $img_array = input('post.img/a'); #获取数组
  791. if ($common_id <= 0 || empty($img_array)) {
  792. ds_json_encode(10001, lang('param_error'));
  793. }
  794. $goods_model = model('goods');
  795. // 删除原有图片信息
  796. $goods_model->delGoodsImages(array('goods_commonid' => $common_id, 'store_id' => session('store_id')));
  797. // 保存
  798. $insert_array = array();
  799. foreach ($img_array as $key => $value) {
  800. $k = 0;
  801. foreach ($value as $v) {
  802. if ($v['name'] == '') {
  803. continue;
  804. }
  805. // 商品默认主图
  806. $update_array = array(); // 更新商品主图
  807. $update_where = array();
  808. $update_array['goods_image'] = $v['name'];
  809. $update_where['goods_commonid'] = $common_id;
  810. $update_where['store_id'] = session('store_id');
  811. $update_where['color_id'] = $key;
  812. if ($k == 0 || $v['default'] == 1) {
  813. $k++;
  814. $update_array['goods_image'] = $v['name'];
  815. $update_where['goods_commonid'] = $common_id;
  816. $update_where['store_id'] = session('store_id');
  817. $update_where['color_id'] = $key;
  818. // 更新商品主图
  819. $goods_model->editGoods($update_array, $update_where);
  820. }
  821. $tmp_insert = array();
  822. $tmp_insert['goods_commonid'] = $common_id;
  823. $tmp_insert['store_id'] = session('store_id');
  824. $tmp_insert['color_id'] = $key;
  825. $tmp_insert['goodsimage_url'] = $v['name'];
  826. $tmp_insert['goodsimage_sort'] = ($v['default'] == 1) ? 0 : intval($v['sort']);
  827. $tmp_insert['goodsimage_isdefault'] = $v['default'];
  828. $insert_array[] = $tmp_insert;
  829. }
  830. }
  831. if (!empty($insert_array)) {
  832. $rs = $goods_model->addGoodsImagesAll($insert_array);
  833. if ($rs) {
  834. // 添加操作日志
  835. $this->recordSellerlog('编辑商品,平台货号:' . $common_id);
  836. ds_json_encode(10000, lang('ds_common_op_succ'));
  837. } else {
  838. ds_json_encode(10001, lang('ds_common_save_fail'));
  839. }
  840. } else {
  841. ds_json_encode(10000, lang('ds_common_op_succ'));
  842. }
  843. }
  844. }
  845. /**
  846. * 编辑分类
  847. */
  848. public function edit_class()
  849. {
  850. // 实例化商品分类模型
  851. $goodsclass_model = model('goodsclass');
  852. // 商品分类
  853. $goods_class = $goodsclass_model->getGoodsclass(session('store_id'));
  854. // 常用商品分类
  855. $staple_model = model('goodsclassstaple');
  856. $param_array = array();
  857. $param_array['member_id'] = session('member_id');
  858. $staple_array = $staple_model->getGoodsclassstapleList($param_array);
  859. View::assign('staple_array', $staple_array);
  860. View::assign('goods_class', $goods_class);
  861. View::assign('commonid', input('param.commonid'));
  862. /* 设置卖家当前菜单 */
  863. $this->setSellerCurMenu('sellergoodsonline');
  864. $this->setSellerCurItem('edit_class');
  865. View::assign('edit_goods_sign', true);
  866. return View::fetch($this->template_dir . 'store_goods_add_step1');
  867. }
  868. /**
  869. * 删除商品
  870. */
  871. public function drop_goods()
  872. {
  873. $commonid = input('param.commonid');
  874. $common_id = $this->checkRequestCommonId($commonid);
  875. $commonid_array = explode(',', $common_id);
  876. $goods_model = model('goods');
  877. $where = array();
  878. $where[] = array('goods_commonid', 'in', $commonid_array);
  879. $where[] = array('store_id', '=', session('store_id'));
  880. $return = $goods_model->delGoodsNoLock($where);
  881. if ($return) {
  882. // 添加操作日志
  883. $this->recordSellerlog('删除商品,平台货号:' . $common_id);
  884. ds_json_encode(10000, lang('store_goods_index_goods_del_success'));
  885. } else {
  886. ds_json_encode(10001, lang('store_goods_index_goods_del_fail'));
  887. }
  888. }
  889. /**
  890. * 商品下架
  891. */
  892. public function goods_unshow()
  893. {
  894. $common_id = $this->checkRequestCommonId(input('param.commonid'));
  895. $commonid_array = explode(',', $common_id);
  896. $goods_model = model('goods');
  897. $where = array();
  898. $where[] = array('goods_commonid', 'in', $commonid_array);
  899. $where[] = array('store_id', '=', session('store_id'));
  900. $return = model('goods')->editProducesOffline($where);
  901. if ($return) {
  902. // 更新优惠套餐状态关闭
  903. $goods_list = $goods_model->getGoodsList($where, 'goods_id');
  904. if (!empty($goods_list)) {
  905. $goodsid_array = array();
  906. foreach ($goods_list as $val) {
  907. $goodsid_array[] = $val['goods_id'];
  908. }
  909. model('pbundling')->editBundlingCloseByGoodsIds(array(array('goods_id', 'in', $goodsid_array)));
  910. }
  911. // 添加操作日志
  912. $this->recordSellerlog('商品下架,平台货号:' . $common_id);
  913. ds_json_encode(10000, lang('store_goods_index_goods_unshow_success'));
  914. } else {
  915. ds_json_encode(10001, lang('store_goods_index_goods_unshow_fail'));
  916. }
  917. }
  918. /**
  919. * 设置排序
  920. */
  921. public function edit_sort()
  922. {
  923. $common_id = $this->checkRequestCommonId(input('param.commonid'));
  924. if (request()->isPost()) {
  925. $goods_sort = input('param.g_sort');
  926. $res1 = model('goods')->editGoodsCommonById(['goods_sort' => $goods_sort], array($common_id));
  927. $res2 = model('goods')->editGoods(['goods_sort' => $goods_sort], ['goods_commonid' => $common_id]);
  928. if ($res1 && $res2) {
  929. // 添加操作日志
  930. $this->recordSellerlog('设置排序,平台货号:' . $common_id);
  931. ds_json_encode(10000, lang('ds_common_op_succ'));
  932. } else {
  933. ds_json_encode(10001, lang('ds_common_op_fail'));
  934. }
  935. }
  936. return View::fetch($this->template_dir . 'edit_sort');
  937. }
  938. /**
  939. * 设置广告词
  940. */
  941. public function edit_jingle()
  942. {
  943. if (request()->isPost()) {
  944. $common_id = $this->checkRequestCommonId(input('param.commonid'));
  945. $commonid_array = explode(',', $common_id);
  946. $where = array(array('goods_commonid', 'in', $commonid_array), array('store_id', '=', session('store_id')));
  947. $update = array('goods_advword' => trim(input('post.g_jingle')));
  948. $return = model('goods')->editProducesNoLock($where, $update);
  949. if ($return) {
  950. // 添加操作日志
  951. $this->recordSellerlog('设置广告词,平台货号:' . $common_id);
  952. ds_json_encode(10000, lang('ds_common_op_succ'));
  953. } else {
  954. ds_json_encode(10001, lang('ds_common_op_fail'));
  955. }
  956. }
  957. $common_id = $this->checkRequestCommonId(input('param.commonid'));
  958. return View::fetch($this->template_dir . 'edit_jingle');
  959. }
  960. /**
  961. * 编辑库存
  962. */
  963. public function edit_storage()
  964. {
  965. $common_id = intval(input('param.commonid'));
  966. if (!$common_id) {
  967. ds_json_encode(10001, lang('param_error'));
  968. }
  969. $goods_model = model('goods');
  970. $goodscommon_info = $goods_model->getGoodsCommonInfoByID($common_id);
  971. if (empty($goodscommon_info) || $goodscommon_info['store_id'] != session('store_id')) {
  972. ds_json_encode(10001, '您的商品不存在,或商品已被锁定,请联系管理员删除促销解除锁定');
  973. }
  974. if (request()->isPost()) {
  975. Db::startTrans();
  976. try {
  977. $spec = input('param.spec/a');
  978. $min_item = array();
  979. foreach ($spec as $goods_id => $val) {
  980. $data = array(
  981. 'goods_weight' => abs(intval($val['goods_weight'])),
  982. 'goods_storage' => abs(intval($val['stock'])),
  983. 'goods_storage_alarm' => abs(intval($val['alarm'])),
  984. 'goods_serial' => $val['sku'],
  985. );
  986. if (!$goodscommon_info['goods_lock']) {
  987. $data['goods_marketprice'] = abs(floatval($val['marketprice']));
  988. $data['goods_price'] = abs(floatval($val['price']));
  989. $data['goods_promotion_price'] = abs(floatval($val['price']));
  990. if ($data['goods_price'] == 0) {
  991. throw new \think\Exception(lang('prompt_information4'), 10006);
  992. }
  993. if ($data['goods_marketprice'] > 0 && $data['goods_price'] > $data['goods_marketprice']) {
  994. throw new \think\Exception(lang('not_higher_than'), 10006);
  995. }
  996. if (empty($min_item) || $min_item['goods_price'] > $data['goods_price']) {
  997. $min_item = $data;
  998. }
  999. }
  1000. $goods_model->editGoods($data, array('goods_commonid' => $common_id, 'goods_id' => $goods_id, 'store_id' => session('store_id')));
  1001. }
  1002. //最低价格
  1003. if (!empty($min_item)) {
  1004. $goods_model->editGoodsCommon(array('goods_discount' => $min_item['goods_marketprice'] > 0 ? intval($min_item['goods_price'] / $min_item['goods_marketprice'] * 100) : 0, 'goods_marketprice' => $min_item['goods_marketprice'], 'goods_price' => $min_item['goods_price']), array('goods_commonid' => $common_id, 'store_id' => session('store_id')));
  1005. }
  1006. } catch (\Exception $e) {
  1007. Db::rollback();
  1008. ds_json_encode(10001, $e->getMessage());
  1009. }
  1010. Db::commit();
  1011. ds_json_encode(10000, lang('ds_common_op_succ'));
  1012. } else {
  1013. View::assign('goodscommon_info', $goodscommon_info);
  1014. $goods_list = $goods_model->getGoodsList(array('goods_commonid' => $common_id, 'store_id' => session('store_id')));
  1015. View::assign('goods_list', $goods_list);
  1016. return View::fetch($this->template_dir . 'edit_storage');
  1017. }
  1018. }
  1019. /**
  1020. * 设置关联版式
  1021. */
  1022. public function edit_plate()
  1023. {
  1024. if (request()->isPost()) {
  1025. $common_id = $this->checkRequestCommonId(input('post.commonid'));
  1026. $commonid_array = explode(',', $common_id);
  1027. $where = array(array('goods_commonid', 'in', $commonid_array), array('store_id', '=', session('store_id')));
  1028. $update = array();
  1029. $update['plateid_top'] = intval(input('post.plate_top')) > 0 ? intval(input('post.plate_top')) : '';
  1030. $update['plateid_bottom'] = intval(input('post.plate_bottom')) > 0 ? intval(input('post.plate_bottom')) : '';
  1031. $return = model('goods')->editGoodsCommon($update, $where);
  1032. if ($return) {
  1033. // 添加操作日志
  1034. $this->recordSellerlog('设置关联版式,平台货号:' . $common_id);
  1035. ds_json_encode(10000, lang('ds_common_op_succ'));
  1036. } else {
  1037. ds_json_encode(10001, lang('ds_common_op_fail'));
  1038. }
  1039. } else {
  1040. $common_id = $this->checkRequestCommonId(input('param.commonid'));
  1041. $plateid_bottom = Db::name('goodscommon')->where(array('goods_commonid' => $common_id))->field('plateid_bottom,plateid_top')->find();
  1042. View::assign('plateid', $plateid_bottom);
  1043. // 关联版式
  1044. $plate_list = model('storeplate')->getStoreplateList(array('store_id' => session('store_id')), 'storeplate_id,storeplate_name,storeplate_position');
  1045. $plate_list = array_under_reset($plate_list, 'storeplate_position', 2);
  1046. View::assign('plate_list', $plate_list);
  1047. return View::fetch($this->template_dir . 'edit_plate');
  1048. }
  1049. }
  1050. /**
  1051. * 添加赠品
  1052. */
  1053. public function add_gift()
  1054. {
  1055. $common_id = intval(input('param.commonid'));
  1056. if ($common_id <= 0) {
  1057. $this->error(lang('param_error'), (string) url('Seller/index'));
  1058. }
  1059. $goods_model = model('goods');
  1060. $goodscommon_info = $goods_model->getGoodsCommonInfoByID($common_id);
  1061. if (empty($goodscommon_info) || $goodscommon_info['store_id'] != session('store_id')) {
  1062. $this->error(lang('param_error'), (string) url('Seller/index'));
  1063. }
  1064. // 商品列表
  1065. $goods_array = $goods_model->getGoodsListForPromotion(array(array('goods_commonid', '=', $common_id)), '*', 0, 'gift');
  1066. View::assign('goods_array', $goods_array);
  1067. // 赠品列表
  1068. $gift_list = model('goodsgift')->getGoodsgiftList(array('goods_commonid' => $common_id));
  1069. $gift_array = array();
  1070. if (!empty($gift_list)) {
  1071. foreach ($gift_list as $val) {
  1072. $gift_array[$val['goods_id']][] = $val;
  1073. }
  1074. }
  1075. View::assign('gift_array', $gift_array);
  1076. /* 设置卖家当前菜单 */
  1077. $this->setSellerCurMenu('sellergoodsonline');
  1078. $this->setSellerCurItem('add_gift');
  1079. return View::fetch($this->template_dir . 'store_goods_edit_add_gift');
  1080. }
  1081. /**
  1082. * 保存赠品
  1083. */
  1084. public function save_gift()
  1085. {
  1086. if (!request()->isPost()) {
  1087. ds_json_encode(10001, lang('param_error'));
  1088. }
  1089. $gift_array = input('post.gift/a', array());
  1090. $commonid = intval(input('param.commonid'));
  1091. if ($commonid <= 0) {
  1092. ds_json_encode(10001, lang('param_error'));
  1093. }
  1094. $goods_model = model('goods');
  1095. $goodsgift_model = model('goodsgift');
  1096. // 验证商品是否存在
  1097. $goods_list = $goods_model->getGoodsListForPromotion(array(array('goods_commonid', '=', $commonid), array('store_id', '=', session('store_id'))), 'goods_id', 0, 'gift');
  1098. if (empty($goods_list)) {
  1099. ds_json_encode(10001, lang('param_error'));
  1100. }
  1101. // 删除该商品原有赠品
  1102. $goodsgift_model->delGoodsgift(array('goods_commonid' => $commonid));
  1103. // 重置商品礼品标记
  1104. $goods_model->editGoods(array('is_have_gift' => 0), array('goods_commonid' => $commonid));
  1105. // 商品id
  1106. $goodsid_array = array();
  1107. foreach ($goods_list as $val) {
  1108. $goodsid_array[] = $val['goods_id'];
  1109. }
  1110. $insert = array();
  1111. $update_goodsid = array();
  1112. foreach ($gift_array as $key => $val) {
  1113. $owner_gid = intval($key); // 主商品id
  1114. // 验证主商品是否为本店铺商品,如果不是本店商品继续下一个循环
  1115. if (!in_array($owner_gid, $goodsid_array)) {
  1116. continue;
  1117. }
  1118. $update_goodsid[] = $owner_gid;
  1119. foreach ($val as $k => $v) {
  1120. $gift_gid = intval($k); // 礼品id
  1121. // 验证赠品是否为本店铺商品,如果不是本店商品继续下一个循环
  1122. $gift_info = $goods_model->getGoodsInfoByID($gift_gid);
  1123. $is_general = $goods_model->checkIsGeneral($gift_info); // 验证是否为普通商品
  1124. if ($gift_info['store_id'] != session('store_id') || $is_general == false) {
  1125. continue;
  1126. }
  1127. $array = array();
  1128. $array['goods_id'] = $owner_gid;
  1129. $array['goods_commonid'] = $commonid;
  1130. $array['gift_goodsid'] = $gift_gid;
  1131. $array['gift_goodsname'] = $gift_info['goods_name'];
  1132. $array['gift_goodsimage'] = $gift_info['goods_image'];
  1133. $array['gift_amount'] = intval($v);
  1134. $insert[] = $array;
  1135. }
  1136. }
  1137. // 插入数据
  1138. if (!empty($insert))
  1139. $goodsgift_model->addGoodsgiftAll($insert);
  1140. // 更新商品赠品标记
  1141. if (!empty($update_goodsid)) {
  1142. $goods_model->editGoodsById(array('is_have_gift' => 1), $update_goodsid);
  1143. }
  1144. ds_json_encode(10000, lang('ds_common_save_succ'));
  1145. }
  1146. /**
  1147. * 推荐搭配
  1148. */
  1149. public function add_combo()
  1150. {
  1151. $common_id = intval(input('param.commonid'));
  1152. if ($common_id <= 0) {
  1153. $this->error(lang('param_error'), (string) url('Seller/index'));
  1154. }
  1155. $goods_model = model('goods');
  1156. $goodscommon_info = $goods_model->getGoodsCommonInfoByID($common_id);
  1157. if (empty($goodscommon_info) || $goodscommon_info['store_id'] != session('store_id')) {
  1158. $this->error(lang('param_error'), (string) url('Seller/index'));
  1159. }
  1160. $goods_array = $goods_model->getGoodsListForPromotion(array(array('goods_commonid', '=', $common_id)), '*', 0, 'combo');
  1161. View::assign('goods_array', $goods_array);
  1162. // 推荐组合商品列表
  1163. $combo_list = model('goodscombo')->getGoodscomboList(array('goods_commonid' => $common_id));
  1164. $combo_goodsid_array = array();
  1165. if (!empty($combo_list)) {
  1166. foreach ($combo_list as $val) {
  1167. $combo_goodsid_array[] = $val['combo_goodsid'];
  1168. }
  1169. }
  1170. $combo_goods_array = $goods_model->getGeneralGoodsList(array(array('goods_id', 'in', $combo_goodsid_array)), 'goods_id,goods_name,goods_image,goods_price');
  1171. $combo_goods_list = array();
  1172. if (!empty($combo_goods_array)) {
  1173. foreach ($combo_goods_array as $val) {
  1174. $combo_goods_list[$val['goods_id']] = $val;
  1175. }
  1176. }
  1177. $combo_array = array();
  1178. foreach ($combo_list as $val) {
  1179. $combo_array[$val['goods_id']][] = $combo_goods_list[$val['combo_goodsid']];
  1180. }
  1181. View::assign('combo_array', $combo_array);
  1182. /* 设置卖家当前菜单 */
  1183. $this->setSellerCurMenu('sellergoodsonline');
  1184. $this->setSellerCurItem('add_combo');
  1185. return View::fetch($this->template_dir . 'store_goods_edit_add_combo');
  1186. }
  1187. /**
  1188. * 保存赠品
  1189. */
  1190. public function save_combo()
  1191. {
  1192. if (!request()->isPost()) {
  1193. ds_json_encode(10001, lang('param_error'));
  1194. }
  1195. $combo_array = input('post.combo/a'); #获取数组
  1196. $commonid = intval(input('param.commonid'));
  1197. if ($commonid <= 0) {
  1198. ds_json_encode(10001, lang('param_error'));
  1199. }
  1200. $goods_model = model('goods');
  1201. $goodscombo_model = model('goodscombo');
  1202. // 验证商品是否存在
  1203. $goods_list = $goods_model->getGoodsListForPromotion(array(array('goods_commonid', '=', $commonid), array('store_id', '=', session('store_id'))), 'goods_id', 0, 'combo');
  1204. if (empty($goods_list)) {
  1205. ds_json_encode(10001, lang('param_error'));
  1206. }
  1207. // 删除该商品原有赠品
  1208. $goodscombo_model->delGoodscombo(array('goods_commonid' => $commonid));
  1209. // 商品id
  1210. $goodsid_array = array();
  1211. foreach ($goods_list as $val) {
  1212. $goodsid_array[] = $val['goods_id'];
  1213. }
  1214. $insert = array();
  1215. if (!empty($combo_array)) {
  1216. foreach ($combo_array as $key => $val) {
  1217. $owner_gid = intval($key); // 主商品id
  1218. // 验证主商品是否为本店铺商品,如果不是本店商品继续下一个循环
  1219. if (!in_array($owner_gid, $goodsid_array)) {
  1220. continue;
  1221. }
  1222. $val = array_unique($val);
  1223. foreach ($val as $v) {
  1224. $combo_gid = intval($v); // 礼品id
  1225. // 验证推荐组合商品是否为本店铺商品,如果不是本店商品继续下一个循环
  1226. $combo_info = $goods_model->getGoodsInfoByID($combo_gid);
  1227. $is_general = $goods_model->checkIsGeneral($combo_info); // 验证是否为普通商品
  1228. if ($combo_info['store_id'] != session('store_id') || $is_general == false || $owner_gid == $combo_gid) {
  1229. continue;
  1230. }
  1231. $array = array();
  1232. $array['goods_id'] = $owner_gid;
  1233. $array['goods_commonid'] = $commonid;
  1234. $array['combo_goodsid'] = $combo_gid;
  1235. $insert[] = $array;
  1236. }
  1237. }
  1238. // 插入数据
  1239. $goodscombo_model->addGoodscomboAll($insert);
  1240. }
  1241. ds_json_encode(10000, lang('ds_common_save_succ'));
  1242. }
  1243. /**
  1244. * 搜索商品(添加赠品/推荐搭配)
  1245. */
  1246. public function search_goods()
  1247. {
  1248. $where = array();
  1249. $where[] = array('store_id', '=', session('store_id'));
  1250. $name = input('param.name');
  1251. if ($name) {
  1252. $where[] = array('goods_name', 'like', '%' . $name . '%');
  1253. }
  1254. $goods_model = model('goods');
  1255. $goods_list = $goods_model->getGeneralGoodsList($where, '*', 5);
  1256. View::assign('show_page', $goods_model->page_info->render());
  1257. View::assign('goods_list', $goods_list);
  1258. echo View::fetch($this->template_dir . 'store_goods_edit_search_goods');
  1259. exit;
  1260. }
  1261. /**
  1262. * 下载F码
  1263. */
  1264. public function download_f_code_excel()
  1265. {
  1266. $common_id = input('param.commonid');
  1267. if ($common_id <= 0) {
  1268. $this->error(lang('param_error'));
  1269. }
  1270. $common_info = model('goods')->getGoodsCommonInfoByID($common_id);
  1271. if (empty($common_info) || $common_info['store_id'] != session('store_id')) {
  1272. $this->error(lang('param_error'));
  1273. }
  1274. $excel_obj = new \excel\Excel();
  1275. $excel_data = array();
  1276. //设置样式
  1277. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  1278. //header
  1279. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('goodsfcode_code'));
  1280. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('goodsfcode_state'));
  1281. $data = model('goodsfcode')->getGoodsfcodeList(array('goods_commonid' => $common_id));
  1282. foreach ($data as $k => $v) {
  1283. $tmp = array();
  1284. $tmp[] = array('data' => $v['goodsfcode_code']);
  1285. $tmp[] = array('data' => $v['goodsfcode_state'] ? lang('goodsfcode_state_1') : lang('goodsfcode_state_0'));
  1286. $excel_data[] = $tmp;
  1287. }
  1288. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  1289. $excel_obj->addArray($excel_data);
  1290. $excel_obj->addWorksheet($excel_obj->charset($common_info['goods_name'], CHARSET));
  1291. $excel_obj->generateXML($excel_obj->charset($common_info['goods_name'], CHARSET) . '-' . date('Y-m-d-H', TIMESTAMP));
  1292. }
  1293. /**
  1294. * 验证commonid
  1295. */
  1296. private function checkRequestCommonId($common_ids)
  1297. {
  1298. if (!preg_match('/^[\d,]+$/i', $common_ids)) {
  1299. ds_json_encode(10001, lang('param_error'));
  1300. }
  1301. return $common_ids;
  1302. }
  1303. /**
  1304. * ajax获取商品列表
  1305. */
  1306. public function get_goods_list_ajax()
  1307. {
  1308. $common_id = input('param.commonid');
  1309. if ($common_id <= 0) {
  1310. echo 'false';
  1311. exit();
  1312. }
  1313. $goods_model = model('goods');
  1314. $goodscommon_list = $goods_model->getGoodsCommonInfoByID($common_id);
  1315. if (empty($goodscommon_list) || $goodscommon_list['store_id'] != session('store_id')) {
  1316. echo 'false';
  1317. exit();
  1318. }
  1319. $goods_list = $goods_model->getGoodsList(array('store_id' => session('store_id'), 'goods_commonid' => $common_id), 'goods_id,goods_spec,store_id,goods_price,goods_serial,goods_storage_alarm,goods_storage,goods_image');
  1320. if (empty($goods_list)) {
  1321. echo 'false';
  1322. exit();
  1323. }
  1324. $spec_name = array_values((array) unserialize($goodscommon_list['spec_name']));
  1325. foreach ($goods_list as $key => $val) {
  1326. $goods_spec = array_values((array) unserialize($val['goods_spec']));
  1327. $spec_array = array();
  1328. foreach ($goods_spec as $k => $v) {
  1329. $spec_array[] = '<div class="goods_spec">' . $spec_name[$k] . lang('ds_colon') . '<em title="' . $v . '">' . $v . '</em>' . '</div>';
  1330. }
  1331. $goods_list[$key]['goods_image'] = goods_thumb($val, '240');
  1332. $goods_list[$key]['goods_spec'] = implode('', $spec_array);
  1333. $goods_list[$key]['alarm'] = ($val['goods_storage_alarm'] != 0 && $val['goods_storage'] <= $val['goods_storage_alarm']) ? 'style="color:red;"' : '';
  1334. $goods_list[$key]['url'] = (string) url('Goods/index', ['goods_id' => $val['goods_id']]);
  1335. }
  1336. echo json_encode($goods_list);
  1337. }
  1338. /**
  1339. * 栏目菜单
  1340. */
  1341. function getSellerItemList()
  1342. {
  1343. $item_list = array(
  1344. array(
  1345. 'name' => 'goods_list',
  1346. 'text' => lang('goods_on_sale'),
  1347. 'url' => (string) url('Sellergoodsonline/index'),
  1348. ),
  1349. );
  1350. if (request()->action() === 'edit_goods' || request()->action() === 'edit_image' || request()->action() === 'add_gift' || request()->action() === 'add_combo' || request()->action() === 'edit_class') {
  1351. $item_list[] = array(
  1352. 'name' => 'edit_goods',
  1353. 'text' => lang('store_goods_index_edit_goods'),
  1354. 'url' => (string) url('Sellergoodsonline/edit_goods', ['commonid' => input('param.commonid')]),
  1355. );
  1356. $item_list[] = array(
  1357. 'name' => 'edit_image',
  1358. 'text' => lang('edit_image'),
  1359. 'url' => (string) url('Sellergoodsonline/edit_image', ['commonid' => input('param.commonid')]),
  1360. );
  1361. $item_list[] = array(
  1362. 'name' => 'add_gift',
  1363. 'text' => lang('add_gift'),
  1364. 'url' => (string) url('Sellergoodsonline/add_gift', ['commonid' => input('param.commonid')]),
  1365. );
  1366. $item_list[] = array(
  1367. 'name' => 'add_combo',
  1368. 'text' => lang('add_combo'),
  1369. 'url' => (string) url('Sellergoodsonline/add_combo', ['commonid' => input('param.commonid')]),
  1370. );
  1371. $item_list[] = array(
  1372. 'name' => 'edit_class',
  1373. 'text' => lang('edit_class'),
  1374. 'url' => (string) url('Sellergoodsonline/edit_class', ['commonid' => input('param.commonid')]),
  1375. );
  1376. }
  1377. return $item_list;
  1378. }
  1379. }