Sellergoodsonline.php 76 KB

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