Sellergoodsonline.php 67 KB

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