Sellergoodsonline.php 76 KB

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