Sellergoodsonline.php 76 KB

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