GoodsModel.class.php 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. use Think\Model;
  16. class GoodsModel extends Model{
  17. /**
  18. 获取商品数量
  19. **/
  20. public function get_goods_count($where = '')
  21. {
  22. $total = M('lionfish_comshop_goods')->where('1 '.$where)->count();
  23. return $total;
  24. }
  25. /**
  26. * 获取抖音真是地址
  27. * @param [type] $url [description]
  28. * @return [type] [description]
  29. */
  30. private function getrealurl($url){
  31. $header = @get_headers($url,1); //默认第二个参数0,可选1,返回关联数组
  32. if(!$header){
  33. return false;
  34. }
  35. if (strpos($header[0],'301') || strpos($header[0],'302')) {
  36. if(is_array($header['location'])) {
  37. return $header['location'][count($header['location'])-1];
  38. }else{
  39. return $header['location'];
  40. }
  41. }else {
  42. return $url;
  43. }
  44. }
  45. public function check_douyin_video( $url )
  46. {
  47. if( strpos($url,'douyin.com') !== false || strpos($url,'iesdouyin.com') !== false )
  48. {
  49. $realUrl = $this->getrealurl($url);
  50. if($realUrl) {
  51. $itemIds = explode('/', $realUrl);
  52. if(count($itemIds)>5) {
  53. $itemId = $itemIds[5];
  54. set_time_limit(0);
  55. $data = file_get_contents('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$itemId);
  56. if($data != '{}'){
  57. $data = json_decode($data, true);
  58. if($data['item_list'] && $data['item_list'][0] && $data['item_list'][0]['video']) {
  59. $vid = $data['item_list'][0]['video']['vid'];
  60. $ratio = $data['item_list'][0]['video']['ratio'];
  61. $vurl = 'https://aweme.snssdk.com/aweme/v1/playwm/?video_id=' . $vid . '&ratio=' . $ratio .'&line=0';
  62. return $vurl;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. return $url;
  69. }
  70. public function _check_douyin_video( $url )
  71. {
  72. if( strpos($url,'douyin.com') !== false || strpos($url,'iesdouyin.com') !== false )
  73. {
  74. $UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
  75. $curl = curl_init();
  76. curl_setopt($curl, CURLOPT_URL, $url);
  77. curl_setopt($curl, CURLOPT_HEADER, 0);
  78. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  79. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  80. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  81. curl_setopt($curl, CURLOPT_ENCODING, '');
  82. curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
  83. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  84. $data = curl_exec($curl);
  85. curl_close($curl);
  86. //获取
  87. preg_match('/<p class="desc">(?<desc>[^<>]*)<\/p>/i', $data, $name);
  88. preg_match('/playAddr: "(?<url>[^"]+)"/i', $data, $url_data);
  89. if( !empty($url_data) )
  90. {
  91. return $url_data[1];
  92. }else{
  93. return $url;
  94. }
  95. }else{
  96. return $url;
  97. }
  98. }
  99. public function addgoods($type = 'normal')
  100. {
  101. $post_data = array();
  102. $post_data_goods = array();
  103. $goodsname = I('post.goodsname','','trim');
  104. $post_data_goods['goodsname'] = addslashes($goodsname);
  105. $post_data_goods['subtitle'] = I('post.subtitle','','trim');
  106. $post_data_goods['grounding'] = I('post.grounding');
  107. $post_data_goods['type'] = $type;
  108. $post_data_goods['price'] = I('post.price');
  109. $post_data_goods['productprice'] = I('post.productprice');
  110. $post_data_goods['card_price'] = I('post.card_price');
  111. $post_data_goods['costprice'] = I('post.costprice');
  112. $post_data_goods['sales'] = I('post.sales');
  113. $post_data_goods['showsales'] = I('post.showsales');
  114. $post_data_goods['dispatchtype'] = I('post.dispatchtype');
  115. $post_data_goods['dispatchid'] = I('post.dispatchid');
  116. $post_data_goods['dispatchprice'] = I('post.dispatchprice');
  117. $post_data_goods['codes'] = I('post.codes','','trim');
  118. $post_data_goods['weight'] = I('post.weight','','trim');
  119. $post_data_goods['total'] = I('post.total','','trim');
  120. $post_data_goods['hasoption'] = I('post.hasoption','','intval');
  121. $post_data_goods['index_sort'] = I('post.index_sort','','intval');
  122. $post_data_goods['credit'] = I('post.credit','','trim');
  123. $post_data_goods['buyagain'] = I('post.buyagain','','trim');
  124. $post_data_goods['buyagain_condition'] = I('post.buyagain_condition','','intval');
  125. $post_data_goods['buyagain_sale'] = I('post.buyagain_sale','','intval');
  126. $post_data_goods['is_index_show'] = I('post.is_index_show','','intval');
  127. $post_data_goods['is_all_sale'] = I('post.is_all_sale','0','intval');
  128. $post_data_goods['is_seckill'] = I('post.is_seckill','0','intval');
  129. $post_data_goods['is_take_vipcard'] = I('post.is_take_vipcard','0','intval');
  130. $post_data_goods['addtime'] = time();
  131. if (defined('ROLE') && ROLE == 'agenter' ) {
  132. $supply_add_goods_shenhe = D('Home/Front')->get_config_by_name('supply_add_goods_shenhe');
  133. if( empty($supply_add_goods_shenhe) )
  134. {
  135. $supply_add_goods_shenhe = 0;
  136. }
  137. if($supply_add_goods_shenhe)
  138. {
  139. $post_data_goods['grounding'] = 4;
  140. }
  141. }
  142. $goods_id = M('lionfish_comshop_goods')->add($post_data_goods);
  143. D('Seller/Operatelog')->addOperateLog('goods','添加商品--'.$post_data_goods['goodsname']);
  144. //find type ,modify somethings TODO...
  145. $pin_type_arr = array(
  146. 'pin'=>'主流团',
  147. 'lottery'=>'抽奖团',
  148. 'oldman'=>'老人团',
  149. 'newman'=>'新人团',
  150. 'commiss'=>'佣金团',
  151. 'ladder'=>'阶梯团',
  152. 'flash'=>'快闪团',
  153. );
  154. $pin_type = array_keys($pin_type_arr);
  155. if( in_array($type, $pin_type) )
  156. {
  157. //插入 拼团商品表 lionfish_comshop_good_pin $time = I('post.time');
  158. $time = I('post.time');
  159. $pin_data['goods_id'] = $goods_id;
  160. $pin_data['pinprice'] = I('post.pinprice');
  161. $pin_data['pin_count'] = I('post.pin_count');
  162. $pin_data['pin_hour'] = I('post.pin_hour');
  163. $pin_data['is_commiss_tuan'] = I('post.is_commiss_tuan',0);
  164. if($pin_data['is_commiss_tuan'] == 1)
  165. {
  166. $pin_data['is_zero_open'] = I('post.is_zero_open',0);
  167. }else{
  168. $pin_data['is_zero_open'] =0;
  169. }
  170. $pin_data['is_newman'] = I('post.is_newman',0);
  171. $commiss_tuan_money1 = I('post.commiss_tuan_money1',0);
  172. $commiss_tuan_money2 = I('post.commiss_tuan_money2',0);
  173. if( isset($commiss_tuan_money1) && $commiss_tuan_money1 >0 )
  174. {
  175. $pin_data['commiss_type'] = 0;
  176. $pin_data['commiss_money'] = $commiss_tuan_money1;
  177. }else{
  178. $pin_data['commiss_type'] = 1;
  179. $pin_data['commiss_money'] = $commiss_tuan_money2;
  180. }
  181. $time = I('post.time');
  182. $pin_data['begin_time'] = strtotime( $time['start'] );
  183. $pin_data['end_time'] = strtotime( $time['end'] );
  184. //拼团返利设置
  185. $pin_data['is_pintuan_rebate'] = I('post.is_pintuan_rebate',0);
  186. if($pin_data['is_pintuan_rebate'] == 1){
  187. $pin_data['random_delivery_count'] = I('post.random_delivery_count',0);
  188. $pin_data['rebate_reward'] = I('post.rebate_reward', 1);
  189. $pin_data['reward_point'] = I('post.reward_point', 0);
  190. $pin_data['reward_balance'] = I('post.reward_balance', 0);
  191. }
  192. M('lionfish_comshop_good_pin')->add( $pin_data );
  193. }
  194. //
  195. //find type ,modify somethings TODO...
  196. $cates = I('post.cate_mult');
  197. if( !empty($cates) )
  198. {
  199. foreach($cates as $cate_id)
  200. {
  201. $post_data_category = array();
  202. $post_data_category['cate_id'] = $cate_id;
  203. $post_data_category['goods_id'] = $goods_id;
  204. M('lionfish_comshop_goods_to_category')->add($post_data_category);
  205. }
  206. }
  207. //lionfish_comshop_goods_images
  208. $thumbs = I('post.thumbs');
  209. if( !empty($thumbs) )
  210. {
  211. foreach($thumbs as $thumbs)
  212. {
  213. $post_data_thumbs = array();
  214. $post_data_thumbs['goods_id'] = $goods_id;
  215. $post_data_thumbs['image'] = save_media($thumbs);
  216. $post_data_thumbs['thumb'] = save_media( resize($thumbs,200,200));
  217. M('lionfish_comshop_goods_images')->add($post_data_thumbs);
  218. }
  219. }
  220. //核销begin
  221. $is_only_hexiao = I('post.is_only_hexiao',0);
  222. if($is_only_hexiao == 1){
  223. $hx_data = array();
  224. $hx_time = time();
  225. $hx_data['goods_id'] = $goods_id;
  226. $hx_data['is_only_hexiao'] = $is_only_hexiao;
  227. $hx_data['hexiao_type'] = I('post.hexiao_type',0);
  228. $hx_data['hx_one_goods_time'] = I('post.hx_one_goods_time',0);
  229. $hx_data['hx_expire_type'] = I('post.hx_expire_type',0);
  230. $hx_data['hx_expire_day'] = I('post.hx_expire_day');
  231. $hx_data['hx_expire_begin_time'] = $hx_time;
  232. if($hx_data['hx_expire_type'] == 1){
  233. $hx_data['hx_expire_end_time'] = strtotime(I('post.hx_expire_end_time'));
  234. }else{
  235. if(empty($hx_data['hx_expire_day'])){
  236. $hx_data['hx_expire_day'] = 90;
  237. }
  238. $hx_data['hx_expire_end_time'] = $hx_time+$hx_data['hx_expire_day']*24*60*60;
  239. }
  240. $hx_data['hx_assign_salesroom'] = I('post.hx_assign_salesroom',0);
  241. $hx_data['hx_auto_off'] = I('post.hx_auto_off',0);
  242. $hx_data['hx_auto_off_time'] = I('post.hx_auto_off_time',0);
  243. $hx_data['addtime'] = $hx_time;
  244. M('lionfish_comshop_goods_salesroombase')->add($hx_data);
  245. if($hx_data['hx_assign_salesroom'] == 1){//指定门店
  246. $goods_room_ids = I('post.goods_room_ids','');
  247. $goods_is_hx_member = I('post.goods_is_hx_member','');
  248. $goods_room_smember = I('post.goods_room_smember','');
  249. if(!empty($goods_room_ids)){
  250. $goods_room_array = explode(',',$goods_room_ids);
  251. foreach($goods_room_array as $grv){
  252. $goods_room_smember_ids = $goods_room_smember[$grv];
  253. $goods_room_data = array();
  254. $goods_room_data['salesroom_id'] = $grv;
  255. $goods_room_data['goods_id'] = $goods_id;
  256. $goods_room_data['is_hx_member'] = $goods_is_hx_member[$grv];
  257. if($goods_is_hx_member[$grv] == 1 && empty($goods_room_smember_ids)){
  258. $goods_room_data['is_hx_member'] = 0;
  259. }
  260. $goods_room_data['addtime'] = $hx_time;
  261. $gr_id = M('lionfish_comshop_goods_relative_salesroom')->add($goods_room_data);
  262. if($gr_id !== false){
  263. $goods_room_smember_ids = $goods_room_smember[$grv];
  264. if($goods_is_hx_member[$grv] == 1 && !empty($goods_room_smember_ids)){
  265. $smember_ids = explode(',',$goods_room_smember_ids);
  266. foreach($smember_ids as $sv){
  267. $room_smember_data = array();
  268. $room_smember_data['salesroom_id'] = $grv;
  269. $room_smember_data['gr_id'] = $gr_id;
  270. $room_smember_data['smember_id'] = $sv;
  271. $room_smember_data['addtime'] = $hx_time;
  272. M('lionfish_comshop_goods_relative_smember')->add($room_smember_data);
  273. }
  274. }
  275. }
  276. }
  277. }
  278. }
  279. }
  280. //核销end
  281. //lionfish_comshop_good_common
  282. $post_data_common = array();
  283. $post_data_common['goods_id'] = $goods_id;
  284. $post_data_common['quality'] = I('post.quality');
  285. $post_data_common['seven'] = I('post.seven');
  286. $post_data_common['repair'] = I('post.repair');
  287. $labelname = I('post.labelname');
  288. $post_data_common['labelname'] = serialize($labelname);
  289. $post_data_common['share_title'] = I('post.share_title');
  290. $post_data_common['share_description'] = I('post.share_description');
  291. $content = I('post.content');
  292. $post_data_common['content'] = htmlspecialchars($content);
  293. $post_data_common['pick_up_type'] = I('post.pick_up_type');
  294. $post_data_common['pick_up_modify'] = I('post.pick_up_modify');
  295. $post_data_common['one_limit_count'] = I('post.one_limit_count');
  296. $post_data_common['oneday_limit_count'] = I('post.oneday_limit_count');
  297. $post_data_common['total_limit_count'] = I('post.total_limit_count');
  298. $post_data_common['community_head_commission'] = I('post.community_head_commission');
  299. $is_community_head_commission = I('post.is_community_head_commission');
  300. $post_data_common['is_community_head_commission'] = $is_community_head_commission;
  301. $post_data_common['goods_start_count'] = I('post.goods_start_count');
  302. $post_data_common['is_show_arrive'] = I('post.is_show_arrive');
  303. $post_data_common['diy_arrive_switch'] = I('post.diy_arrive_switch');
  304. $post_data_common['diy_arrive_details'] = I('post.diy_arrive_details');
  305. $post_data_common['is_new_buy'] = I('post.is_new_buy');
  306. $post_data_common['is_spike_buy'] = I('post.is_spike_buy');
  307. if (defined('ROLE') && ROLE == 'agenter' )
  308. {
  309. $supply_can_goods_sendscore = D('Home/Front')->get_config_by_name('supply_can_goods_sendscore');
  310. if($supply_can_goods_sendscore == 1){
  311. $post_data_common['is_modify_sendscore'] = I('post.is_modify_sendscore',0);
  312. $post_data_common['send_socre'] = I('post.send_socre');
  313. }
  314. }else{
  315. $post_data_common['is_modify_sendscore'] = I('post.is_modify_sendscore',0);
  316. $post_data_common['send_socre'] = I('post.send_socre');
  317. }
  318. $post_data_common['is_mb_level_buy'] = I('post.is_mb_level_buy', 1);
  319. //$post_data_common['supply_id'] = I('post.supply_id');
  320. if (defined('ROLE') && ROLE == 'agenter' )
  321. {
  322. $supper_info = get_agent_logininfo();
  323. $post_data_common['supply_id'] = $supper_info['id'];
  324. }else{
  325. $post_data_common['supply_id'] = I('post.supply_id');
  326. }
  327. $time = I('post.time');
  328. $post_data_common['begin_time'] = strtotime( $time['start'] );
  329. $post_data_common['end_time'] = strtotime( $time['end'] );
  330. $big_img =I('post.big_img');
  331. $goods_share_image =I('post.goods_share_image');
  332. $post_data_common['big_img'] = save_media($big_img);
  333. $post_data_common['goods_share_image'] = save_media($goods_share_image);
  334. $post_data_common['video'] = save_media(I('post.video'));
  335. $post_data_common['video'] = $this->check_douyin_video($post_data_common['video']);
  336. $post_data_common['print_sub_title'] = I('post.print_sub_title');
  337. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  338. $post_data_common['is_only_express'] = I('post.is_only_express',0);
  339. $post_data_common['is_only_hexiao'] = $is_only_hexiao;
  340. $post_data_common['packing_free'] = I('post.packing_free',0);
  341. if( $post_data_common['is_only_express'] == 1 )
  342. {
  343. $post_data_common['is_only_distribution'] = 0;
  344. }else {
  345. $is_only_distribution = I('post.is_only_distribution');
  346. $post_data_common['is_only_distribution'] = $is_only_distribution;
  347. }
  348. $post_data_common['is_limit_levelunbuy'] = I('post.is_limit_levelunbuy',0);
  349. $post_data_common['is_limit_vipmember_buy'] = I('post.is_limit_vipmember_buy',0);
  350. if( empty($is_open_fullreduction) )
  351. {
  352. $post_data_common['is_take_fullreduction'] = 1;
  353. }else if( $is_open_fullreduction ==0 )
  354. {
  355. }else if($is_open_fullreduction ==1){
  356. $post_data_common['is_take_fullreduction'] = I('post.is_take_fullreduction' ,1);
  357. }
  358. if($post_data_common['is_take_fullreduction'] == 1 && $post_data_common['supply_id'] > 0)
  359. {
  360. $supply_info = M('lionfish_comshop_supply')->field('type')->where( array('id' => $post_data_common['supply_id'] ) )->find();
  361. if( !empty($supply_info) && $supply_info['type'] == 1 )
  362. {
  363. $post_data_common['is_take_fullreduction'] = 0;
  364. }
  365. }
  366. //begin
  367. /**
  368. $is_modify_head_commission = I('post.is_modify_head_commission','0','intval');
  369. if( isset($is_modify_head_commission) )
  370. {
  371. $post_data_common['is_modify_head_commission'] = $is_modify_head_commission;
  372. **/
  373. $is_modify_head_commission = I('post.is_modify_head_commission','0','intval');
  374. if( isset($is_modify_head_commission) )
  375. {
  376. $post_data_common['is_modify_head_commission'] = $is_modify_head_commission;
  377. if( $post_data_common['is_modify_head_commission'] == 1 )
  378. {
  379. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  380. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  381. $default_comunity_money = D('Home/Front')->get_config_by_name('head_commission_levelname');
  382. $list_default = array(
  383. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  384. );
  385. $community_head_level = array_merge($list_default, $community_head_level);
  386. $community_head_commission_modify = array();
  387. foreach($community_head_level as $kk => $vv)
  388. {
  389. $community_head_commission_modify['head_level'.$vv['id']] = I('post.head_level'.$vv['id']);
  390. }
  391. if( !isset($is_community_head_commission)){
  392. $post_data_common['community_head_commission'] = $community_head_commission_modify['head_level0'];
  393. }
  394. $post_data_common['community_head_commission_modify'] = serialize($community_head_commission_modify);
  395. }
  396. }else{
  397. $post_data_common['is_modify_head_commission'] = 0;
  398. }
  399. $relative_goods_list = array();
  400. $limit_goods_list = I('post.limit_goods_list');
  401. if( isset($limit_goods_list) && !empty($limit_goods_list) )
  402. {
  403. $limit_goods_list = explode(',', $limit_goods_list);
  404. $relative_goods_list = $limit_goods_list;
  405. }
  406. $post_data_common['relative_goods_list'] = serialize($relative_goods_list);
  407. $post_data_common['has_mb_level_buy'] = I('post.has_mb_level_buy',0,'intval');
  408. $level_id_list = I('post.level_id');
  409. $discount_list = I('post.discount');
  410. $mb_level_buy_list = array();
  411. if(isset($level_id_list) && !empty($level_id_list)){
  412. for($i = 0;$i < count($level_id_list);$i++){
  413. $level_list = array();
  414. $level_list['level_id'] = $level_id_list[$i];
  415. if(!is_numeric($discount_list[$i])){
  416. $level_list['discount'] = 0;
  417. }else{
  418. if($discount_list[$i] < 0 && $discount_list[$i] > 100){
  419. $level_list['discount'] = 0;
  420. }else{
  421. $level_list['discount'] = $discount_list[$i];
  422. }
  423. }
  424. $mb_level_buy_list[] = $level_list;
  425. }
  426. }
  427. $post_data_common['mb_level_buy_list'] = serialize($mb_level_buy_list);
  428. //end
  429. M('lionfish_comshop_good_common')->add($post_data_common);
  430. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  431. //规格
  432. $hasoption = I('post.hasoption');
  433. if( intval($hasoption) == 1 )
  434. {
  435. $mult_option_item_dan_key = array();
  436. $replace_option_item_id_arr = array();//需要更替的option_item_id
  437. $save_goods_option_arr = array();
  438. $spec_id = I('post.spec_id');
  439. if( isset($spec_id) && !empty($spec_id) )
  440. {
  441. $option_order = 1;
  442. foreach($spec_id as $spec_id)
  443. {
  444. $spec_title = I('post.spec_title');
  445. //规格标题
  446. $cur_spec_title = $spec_title[$spec_id];
  447. $goods_option_data = array();
  448. $goods_option['goods_id'] = $goods_id;
  449. $goods_option['title'] = $cur_spec_title;
  450. $goods_option['displayorder'] = $option_order;
  451. $option_id = M('lionfish_comshop_goods_option')->add($goods_option);
  452. $save_goods_option_arr[] = $option_id;
  453. $spec_item_title_t = 'post.spec_item_title_'.$spec_id;
  454. $spec_item_title_arr = I($spec_item_title_t);
  455. if(!empty($spec_item_title_arr))
  456. {
  457. $item_sort = 1;
  458. $i = 0;
  459. $j = 0;
  460. foreach($spec_item_title_arr as $key =>$item_title)
  461. {
  462. $goods_option_item_data = array();
  463. $goods_option_item_data['goods_id'] = $goods_id;
  464. $goods_option_item_data['goods_option_id'] = $option_id;
  465. $goods_option_item_data['title'] = $item_title;
  466. $thumb_t = I('post.spec_item_thumb_'.$spec_id);
  467. // $_GPC['spec_item_thumb_'.$spec_id]
  468. $goods_option_item_data['thumb'] = $thumb_t[$key];
  469. $goods_option_item_data['displayorder'] = $item_sort;
  470. $new_option_item_id = M('lionfish_comshop_goods_option_item')->add($goods_option_item_data);
  471. $replace_option_item_id_arr[$option_item_id] = $new_option_item_id;
  472. $option_item_id = $new_option_item_id;
  473. //从小到大的排序
  474. $t_k_arr = I('post.spec_item_id_'.$spec_id);
  475. $mult_option_item_dan_key[ $t_k_arr[$key] ] = $option_item_id;
  476. $item_sort++;
  477. $i++;
  478. }
  479. }else{
  480. M('lionfish_comshop_goods_option')->where( array('id' => $id) )->delete();
  481. }
  482. $option_order++;
  483. }
  484. }
  485. $option_ids_arr = I('post.option_ids');
  486. $total = 0;
  487. foreach($option_ids_arr as $val)
  488. {
  489. $option_item_ids = '';
  490. $option_item_ids_arr = array();
  491. $key_items = explode('_', $val);
  492. $new_val = array();
  493. foreach($key_items as $vv)
  494. {
  495. if( isset($replace_option_item_id_arr[$vv]) )
  496. {
  497. $option_item_ids_arr[] = $replace_option_item_id_arr[$vv];
  498. }else{
  499. $option_item_ids_arr[] = $mult_option_item_dan_key[$vv];
  500. }
  501. $new_val[] = $vv;
  502. }
  503. asort($option_item_ids_arr);
  504. $option_item_ids = implode('_', $option_item_ids_arr);
  505. $snailfish_goods_option_item_value_data = array();
  506. $snailfish_goods_option_item_value_data['goods_id'] = $goods_id;
  507. $snailfish_goods_option_item_value_data['option_item_ids'] = $option_item_ids;
  508. $productprice = I('post.option_productprice_'.$val);
  509. $snailfish_goods_option_item_value_data['productprice'] = $productprice;
  510. $pinprice = I('post.option_presell_'.$val);
  511. $snailfish_goods_option_item_value_data['pinprice'] = $pinprice;
  512. $marketprice = I('post.option_marketprice_'.$val);
  513. $snailfish_goods_option_item_value_data['marketprice'] = $marketprice;
  514. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  515. {
  516. $card_price = I('post.option_cardprice_'.$val);
  517. $snailfish_goods_option_item_value_data['card_price'] = $card_price;
  518. }
  519. $stock = I('post.option_stock_'.$val);
  520. $costprice = I('post.option_costprice_'.$val);
  521. $goodssn = I('post.option_goodssn_'.$val);
  522. $weight = I('post.option_weight_'.$val);
  523. $title = I('post.option_title_'.$val);
  524. $snailfish_goods_option_item_value_data['stock'] = $stock;
  525. $snailfish_goods_option_item_value_data['costprice'] = $costprice;
  526. $snailfish_goods_option_item_value_data['goodssn'] = $goodssn;
  527. $snailfish_goods_option_item_value_data['weight'] = $weight;
  528. $snailfish_goods_option_item_value_data['title'] = $title ;
  529. $total += $snailfish_goods_option_item_value_data['stock'];
  530. M('lionfish_comshop_goods_option_item_value')->add($snailfish_goods_option_item_value_data);
  531. }
  532. //更新库存 total
  533. $up_goods_data = array();
  534. $up_goods_data['total'] = $total;
  535. M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->save( $up_goods_data );
  536. if( !empty($save_goods_option_arr) )
  537. {
  538. foreach( $save_goods_option_arr as $k_option_id )
  539. {
  540. $tp_item_val = M('lionfish_comshop_goods_option_item')->where( array('goods_option_id' => $k_option_id ) )->find();
  541. if( empty($tp_item_val) )
  542. {
  543. M('lionfish_comshop_goods_option')->where( array('id' => $k_option_id ) )->delete();
  544. }
  545. }
  546. }
  547. }
  548. if( isset($_POST['presale_type']) )
  549. {
  550. D('Seller/GoodsPresale')->modifyGoodsPresale( $goods_id );
  551. }
  552. //虚拟卡密
  553. if( isset($_POST['is_virtualcard_goods']) && $_POST['is_virtualcard_goods'] == 1 )
  554. {
  555. D('Seller/VirtualCard')->modifyGoodsVirtualCard( $goods_id );
  556. }
  557. //规格插入
  558. $post_data_commiss = array();
  559. $post_data_commiss['goods_id'] = $goods_id;
  560. $post_data_commiss['nocommission'] = I('post.nocommission',0,'intval');
  561. $post_data_commiss['hascommission'] = I('post.hascommission',0,'intval');
  562. $post_data_commiss['commission_type'] = I('post.commission_type',0,'intval');
  563. $post_data_commiss['commission1_rate'] = I('post.commission1_rate');
  564. $post_data_commiss['commission1_pay'] = I('post.commission1_pay');
  565. $post_data_commiss['commission2_rate'] = I('post.commission2_rate');
  566. $post_data_commiss['commission2_pay'] = I('post.commission2_pay');
  567. $post_data_commiss['commission3_rate'] = I('post.commission3_rate');
  568. $post_data_commiss['commission3_pay'] = I('post.commission3_pay');
  569. M('lionfish_comshop_good_commiss')->add( $post_data_commiss );
  570. //售卖团长插入
  571. $head_id_arr = I('request.head_id_arr');
  572. if(!empty($head_id_arr)){
  573. $head_ids = explode(",",$head_id_arr);
  574. foreach($head_ids as $head_id)
  575. {
  576. D('Seller/Communityhead')->insert_head_goods($goods_id, $head_id);
  577. }
  578. }
  579. D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  580. }
  581. /**
  582. 获取编辑的商品资料
  583. **/
  584. public function get_edit_goods_info($id,$is_pin =0)
  585. {
  586. $item = M('lionfish_comshop_goods')->where( array('id' => $id) )->find();
  587. $cates_arr = M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $id) )->order('id asc')->select();
  588. $cates = array();
  589. foreach($cates_arr as $val)
  590. {
  591. $cates[] = $val['cate_id'];
  592. }
  593. $item['cates'] = $cates;
  594. $piclist = array();
  595. //ims_lionfish_comshop_goods_images labelname[]
  596. $piclist_arr = M('lionfish_comshop_goods_images')->where( array('goods_id' => $id ) )->order('id asc')->select();
  597. foreach($piclist_arr as $val)
  598. {
  599. if( empty($val['thumb'] ) )
  600. {
  601. $val['thumb'] = $val['image'];
  602. }
  603. //image
  604. $piclist[] = array('image' =>$val['image'], 'thumb' => $val['thumb'] ); //$val['image'];
  605. }
  606. //$item['piclist']
  607. $item['piclist'] = $piclist;
  608. $item_common = M('lionfish_comshop_good_common')->where( array('goods_id' => $id) )->find();
  609. $item = array_merge($item,$item_common);
  610. if( $item['supply_id'] >0 )
  611. {
  612. $supply_info = M('lionfish_comshop_supply')->where( array('id' => $item['supply_id']) )->find();
  613. if(!empty($supply_info) )
  614. {
  615. $supply_info['supply_id'] = $supply_info['id'];
  616. $supply_info['logo'] = ($supply_info['logo']);
  617. }
  618. $item['supply_info'] = $supply_info;
  619. }
  620. //item
  621. $pin_type_arr = array(
  622. 'pin'=>'主流团',
  623. 'lottery'=>'抽奖团',
  624. 'oldman'=>'老人团',
  625. 'newman'=>'新人团',
  626. 'commiss'=>'佣金团',
  627. 'ladder'=>'阶梯团',
  628. 'flash'=>'快闪团',
  629. );
  630. $pin_type = array_keys($pin_type_arr);
  631. if( in_array($item['type'], $pin_type) )
  632. {
  633. $pin_item = M('lionfish_comshop_good_pin')->where( array('goods_id' => $id ) )->find();
  634. $item = array_merge($item,$pin_item);
  635. }
  636. //核销 begin TODO....
  637. //核销 end
  638. $label_id = unserialize($item['labelname']);
  639. $label = array();
  640. if($label_id){
  641. $label = D('Home/Pingoods')->get_goods_tags($label_id);
  642. }
  643. $item['label'] = $label;
  644. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  645. //TODO.20181219
  646. $allspecs = M('lionfish_comshop_goods_option')->where( array('goods_id' => $id) )->order('displayorder asc')->select();
  647. foreach ($allspecs as &$s ) {
  648. $s['items'] = M('lionfish_comshop_goods_option_item')->field('id,goods_option_id,title,thumb,displayorder')->where( array('goods_option_id' =>$s['id'] ) )->order('displayorder asc')->select();
  649. }
  650. $item['allspecs'] = $allspecs;
  651. //allspecs //html
  652. $html = '';
  653. $options = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $id) )->order('id asc')->select();
  654. $specs = array();
  655. if (0 < count($options)) {
  656. $specitemids = explode('_', $options[0]['option_item_ids']);
  657. foreach ($specitemids as $itemid ) {
  658. foreach ($allspecs as $ss ) {
  659. $items = $ss['items'];
  660. foreach ($items as $it ) {
  661. while ($it['id'] == $itemid) {
  662. $specs[] = $ss;
  663. break;
  664. }
  665. }
  666. }
  667. }
  668. $html = '';
  669. $html .= '<table class="table table-bordered table-condensed">';
  670. $html .= '<thead>';
  671. $html .= '<tr class="active">';
  672. $discounts_html .= '<table class="table table-bordered table-condensed">';
  673. $discounts_html .= '<thead>';
  674. $discounts_html .= '<tr class="active">';
  675. $commission_html .= '<table class="table table-bordered table-condensed">';
  676. $commission_html .= '<thead>';
  677. $commission_html .= '<tr class="active">';
  678. $isdiscount_discounts_html .= '<table class="table table-bordered table-condensed">';
  679. $isdiscount_discounts_html .= '<thead>';
  680. $isdiscount_discounts_html .= '<tr class="active">';
  681. $len = count($specs);
  682. $newlen = 1;
  683. $h = array();
  684. $rowspans = array();
  685. $i = 0;
  686. while ($i < $len) {
  687. $html .= '<th>' . $specs[$i]['title'] . '</th>';
  688. $discounts_html .= '<th>' . $specs[$i]['title'] . '</th>';
  689. $commission_html .= '<th>' . $specs[$i]['title'] . '</th>';
  690. $isdiscount_discounts_html .= '<th>' . $specs[$i]['title'] . '</th>';
  691. $itemlen = count($specs[$i]['items']);
  692. if ($itemlen <= 0) {
  693. $itemlen = 1;
  694. }
  695. $newlen *= $itemlen;
  696. $h = array();
  697. $j = 0;
  698. while ($j < $newlen) {
  699. $h[$i][$j] = array();
  700. ++$j;
  701. }
  702. $l = count($specs[$i]['items']);
  703. $rowspans[$i] = 1;
  704. $j = $i + 1;
  705. while ($j < $len) {
  706. $rowspans[$i] *= count($specs[$j]['items']);
  707. ++$j;
  708. }
  709. ++$i;
  710. }
  711. $canedit = true;
  712. if ($canedit) {
  713. if(!empty($levels))
  714. {
  715. foreach ($levels as $level ) {
  716. $discounts_html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">' . $level['levelname'] . '</div><div class="input-group"><input type="text" class="form-control input-sm discount_' . $level['key'] . '_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'discount_' . $level['key'] . '\');"></a></span></div></div></th>';
  717. $isdiscount_discounts_html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">' . $level['levelname'] . '</div><div class="input-group"><input type="text" class="form-control input-sm isdiscount_discounts_' . $level['key'] . '_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'isdiscount_discounts_' . $level['key'] . '\');"></a></span></div></div></th>';
  718. }
  719. }
  720. if( !empty($commission_level) )
  721. {
  722. foreach ($commission_level as $level ) {
  723. $commission_html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">' . $level['levelname'] . '</div></div></th>';
  724. }
  725. }
  726. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">库存<label style="color:red;font-size:16px;font-weight:900">*</label></div><div class="input-group"><input type="text" class="form-control input-sm option_stock_all" VALUE=""/><span class="input-group-addon" ><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
  727. if($is_pin == 1)
  728. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">拼团价<label style="font-size:16px;font-weight:900;color: #ff0000;">*</label> </div><div class="input-group"><input type="text" class="form-control input-sm option_presell_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_presell\');"></a></span></div></div></th>';
  729. if( $item['type'] == 'integral' )
  730. {
  731. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">兑换积分</div><div class="input-group"><input type="text" class="form-control input-sm option_marketprice_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
  732. }else{
  733. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">售价<label style="color:red;font-size:16px;font-weight:900">*</label></div><div class="input-group"><input type="text" class="form-control input-sm option_marketprice_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
  734. }
  735. if($item['type'] != 'integral' && $is_pin == 0 && !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 && isset($item['is_take_vipcard']) && $item['is_take_vipcard'] == 1)
  736. {
  737. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">付费会员专享价</div><div class="input-group"><input type="text" class="form-control input-sm option_cardprice_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_cardprice\');"></a></span></div></div></th>';
  738. }
  739. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">原价<label style="color:red;font-size:16px;font-weight:900">*</label></div><div class="input-group"><input type="text" class="form-control input-sm option_productprice_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
  740. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">成本价</div><div class="input-group"><input type="text" class="form-control input-sm option_costprice_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_costprice\');"></a></span></div></div></th>';
  741. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">编码</div><div class="input-group"><input type="text" class="form-control input-sm option_goodssn_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_goodssn\');"></a></span></div></div></th>';
  742. //$html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">条码</div><div class="input-group"><input type="text" class="form-control input-sm option_productsn_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_productsn\');"></a></span></div></div></th>';
  743. $html .= '<th><div class=""><div style="padding-bottom:10px;text-align:center;">重量(克)</div><div class="input-group"><input type="text" class="form-control input-sm option_weight_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
  744. }
  745. $html .= '</tr></thead>';
  746. $discounts_html .= '</tr></thead>';
  747. $isdiscount_discounts_html .= '</tr></thead>';
  748. $commission_html .= '</tr></thead>';
  749. $m = 0;
  750. while ($m < $len) {
  751. $k = 0;
  752. $kid = 0;
  753. $n = 0;
  754. $j = 0;
  755. while ($j < $newlen) {
  756. $rowspan = $rowspans[$m];
  757. if (($j % $rowspan) == 0) {
  758. $h[$m][$j] = array('html' => '<td class=\'full\' rowspan=\'' . $rowspan . '\'>' . $specs[$m]['items'][$kid]['title'] . '</td>', 'id' => $specs[$m]['items'][$kid]['id']);
  759. }
  760. else {
  761. $h[$m][$j] = array('html' => '', 'id' => $specs[$m]['items'][$kid]['id']);
  762. }
  763. ++$n;
  764. if ($n == $rowspan) {
  765. ++$kid;
  766. if ((count($specs[$m]['items']) - 1) < $kid) {
  767. $kid = 0;
  768. }
  769. $n = 0;
  770. }
  771. ++$j;
  772. }
  773. ++$m;
  774. }
  775. $hh = '';
  776. $dd = '';
  777. $isdd = '';
  778. $cc = '';
  779. $i = 0;
  780. while ($i < $newlen) {
  781. $hh .= '<tr>';
  782. $dd .= '<tr>';
  783. $isdd .= '<tr>';
  784. $cc .= '<tr>';
  785. $ids = array();
  786. $j = 0;
  787. while ($j < $len) {
  788. $hh .= $h[$j][$i]['html'];
  789. $dd .= $h[$j][$i]['html'];
  790. $isdd .= $h[$j][$i]['html'];
  791. $cc .= $h[$j][$i]['html'];
  792. $ids[] = $h[$j][$i]['id'];
  793. ++$j;
  794. }
  795. asort($ids);
  796. $ids = implode('_', $ids);
  797. $val = array('id' => '', 'title' => '', 'stock' => '', 'presell' => '', 'costprice' => '','card_price' => '', 'productprice' => '', 'marketprice' => '', 'weight' => '', 'virtual' => '');
  798. $discounts_val = array('id' => '', 'title' => '', 'level' => '', 'costprice' => '', 'productprice' => '', 'marketprice' => '', 'weight' => '', 'virtual' => '');
  799. $isdiscounts_val = array('id' => '', 'title' => '', 'level' => '', 'costprice' => '', 'productprice' => '', 'marketprice' => '', 'weight' => '', 'virtual' => '');
  800. $commission_val = array('id' => '', 'title' => '', 'level' => '', 'costprice' => '', 'productprice' => '', 'marketprice' => '', 'weight' => '', 'virtual' => '');
  801. if(!empty($levels)) {
  802. foreach ($levels as $level ) {
  803. $discounts_val[$level['key']] = '';
  804. $isdiscounts_val[$level['key']] = '';
  805. }
  806. }
  807. if(!empty($commission_level)){
  808. foreach ($commission_level as $level ) {
  809. $commission_val[$level['key']] = '';
  810. }
  811. }
  812. foreach ($options as $o ) {
  813. while ($ids === $o['option_item_ids']) {
  814. $val = array('id' => $o['id'], 'title' => $o['title'], 'stock' => $o['stock'], 'costprice' => $o['costprice'],'card_price' => $o['card_price'] , 'productprice' => $o['productprice'], 'pinprice' => $o['pinprice'], 'marketprice' => $o['marketprice'], 'goodssn' => $o['goodssn'], 'productsn' => $o['productsn'], 'weight' => $o['weight'], 'virtual' => $o['virtual']);
  815. $discount_val = array('id' => $o['id']);
  816. if(!empty($levels))
  817. {
  818. foreach ($levels as $level ) {
  819. $discounts_val[$level['key']] = ((is_string($discounts[$level['key']]) ? '' : $discounts[$level['key']]['option' . $o['id']]));
  820. $isdiscounts_val[$level['key']] = ((is_string($isdiscount_discounts[$level['key']]) ? '' : $isdiscount_discounts[$level['key']]['option' . $o['id']]));
  821. }
  822. }
  823. $commission_val = array();
  824. if(!empty($commission_level))
  825. {
  826. foreach ($commission_level as $level ) {
  827. $temp = ((is_string($commission[$level['key']]) ? '' : $commission[$level['key']]['option' . $o['id']]));
  828. if (is_array($temp)) {
  829. foreach ($temp as $t_val ) {
  830. $commission_val[$level['key']][] = $t_val;
  831. }
  832. }
  833. }
  834. }
  835. unset($temp);
  836. break;
  837. }
  838. }
  839. if ($canedit) {
  840. if( !empty($levels) )
  841. {
  842. foreach ($levels as $level ) {
  843. $dd .= '<td>';
  844. $isdd .= '<td>';
  845. if ($level['key'] == 'default') {
  846. $dd .= '<input data-name="discount_level_' . $level['key'] . '_' . $ids . '" type="text" class="form-control discount_' . $level['key'] . ' discount_' . $level['key'] . '_' . $ids . '" value="' . $discounts_val[$level['key']] . '"/> ';
  847. $isdd .= '<input data-name="isdiscount_discounts_level_' . $level['key'] . '_' . $ids . '" type="text" class="form-control isdiscount_discounts_' . $level['key'] . ' isdiscount_discounts_' . $level['key'] . '_' . $ids . '" value="' . $isdiscounts_val[$level['key']] . '"/> ';
  848. }
  849. else {
  850. $dd .= '<input data-name="discount_level_' . $level['id'] . '_' . $ids . '" type="text" class="form-control discount_level' . $level['id'] . ' discount_level' . $level['id'] . '_' . $ids . '" value="' . $discounts_val['level' . $level['id']] . '"/> ';
  851. $isdd .= '<input data-name="isdiscount_discounts_level_' . $level['id'] . '_' . $ids . '" type="text" class="form-control isdiscount_discounts_level' . $level['id'] . ' isdiscount_discounts_level' . $level['id'] . '_' . $ids . '" value="' . $isdiscounts_val['level' . $level['id']] . '"/> ';
  852. }
  853. $dd .= '</td>';
  854. $isdd .= '</td>';
  855. }
  856. }
  857. $dd .= '<input data-name="discount_id_' . $ids . '" type="hidden" class="form-control discount_id discount_id_' . $ids . '" value="' . $discounts_val['id'] . '"/>';
  858. $dd .= '<input data-name="discount_ids" type="hidden" class="form-control discount_ids discount_ids_' . $ids . '" value="' . $ids . '"/>';
  859. $dd .= '<input data-name="discount_title_' . $ids . '" type="hidden" class="form-control discount_title discount_title_' . $ids . '" value="' . $discounts_val['title'] . '"/>';
  860. $dd .= '<input data-name="discount_virtual_' . $ids . '" type="hidden" class="form-control discount_title discount_virtual_' . $ids . '" value="' . $discounts_val['virtual'] . '"/>';
  861. $dd .= '</tr>';
  862. $isdd .= '<input data-name="isdiscount_discounts_id_' . $ids . '" type="hidden" class="form-control isdiscount_discounts_id isdiscount_discounts_id_' . $ids . '" value="' . $isdiscounts_val['id'] . '"/>';
  863. $isdd .= '<input data-name="isdiscount_discounts_ids" type="hidden" class="form-control isdiscount_discounts_ids isdiscount_discounts_ids_' . $ids . '" value="' . $ids . '"/>';
  864. $isdd .= '<input data-name="isdiscount_discounts_title_' . $ids . '" type="hidden" class="form-control isdiscount_discounts_title isdiscount_discounts_title_' . $ids . '" value="' . $isdiscounts_val['title'] . '"/>';
  865. $isdd .= '<input data-name="isdiscount_discounts_virtual_' . $ids . '" type="hidden" class="form-control isdiscount_discounts_title isdiscount_discounts_virtual_' . $ids . '" value="' . $isdiscounts_val['virtual'] . '"/>';
  866. $isdd .= '</tr>';
  867. if(!empty($commission_level)){
  868. foreach ($commission_level as $level ) {
  869. $cc .= '<td>';
  870. if (!(empty($commission_val)) && isset($commission_val[$level['key']])) {
  871. foreach ($commission_val as $c_key => $c_val ) {
  872. if ($c_key == $level['key']) {
  873. if ($level['key'] == 'default') {
  874. $c_i = 0;
  875. while ($c_i < $shopset_level) {
  876. $cc .= '<input data-name="commission_level_' . $level['key'] . '_' . $ids . '" type="text" class="form-control commission_' . $level['key'] . ' commission_' . $level['key'] . '_' . $ids . '" value="' . $c_val[$c_i] . '" style="display:inline;width: ' . (96 / $shopset_level) . '%;"/> ';
  877. ++$c_i;
  878. }
  879. }
  880. else {
  881. $c_i = 0;
  882. while ($c_i < $shopset_level) {
  883. $cc .= '<input data-name="commission_level_' . $level['id'] . '_' . $ids . '" type="text" class="form-control commission_level' . $level['id'] . ' commission_level' . $level['id'] . '_' . $ids . '" value="' . $c_val[$c_i] . '" style="display:inline;width: ' . (96 / $shopset_level) . '%;"/> ';
  884. ++$c_i;
  885. }
  886. }
  887. }
  888. }
  889. }
  890. else if ($level['key'] == 'default') {
  891. $c_i = 0;
  892. while ($c_i < $shopset_level) {
  893. $cc .= '<input data-name="commission_level_' . $level['key'] . '_' . $ids . '" type="text" class="form-control commission_' . $level['key'] . ' commission_' . $level['key'] . '_' . $ids . '" value="" style="display:inline;width: ' . (96 / $shopset_level) . '%;"/> ';
  894. ++$c_i;
  895. }
  896. }
  897. else {
  898. $c_i = 0;
  899. while ($c_i < $shopset_level) {
  900. $cc .= '<input data-name="commission_level_' . $level['id'] . '_' . $ids . '" type="text" class="form-control commission_level' . $level['id'] . ' commission_level' . $level['id'] . '_' . $ids . '" value="" style="display:inline;width: ' . (96 / $shopset_level) . '%;"/> ';
  901. ++$c_i;
  902. }
  903. }
  904. $cc .= '</td>';
  905. }
  906. }
  907. $cc .= '<input data-name="commission_id_' . $ids . '" type="hidden" class="form-control commission_id commission_id_' . $ids . '" value="' . $commissions_val['id'] . '"/>';
  908. $cc .= '<input data-name="commission_ids" type="hidden" class="form-control commission_ids commission_ids_' . $ids . '" value="' . $ids . '"/>';
  909. $cc .= '<input data-name="commission_title_' . $ids . '" type="hidden" class="form-control commission_title commission_title_' . $ids . '" value="' . $commissions_val['title'] . '"/>';
  910. $cc .= '<input data-name="commission_virtual_' . $ids . '" type="hidden" class="form-control commission_title commission_virtual_' . $ids . '" value="' . $commissions_val['virtual'] . '"/>';
  911. $cc .= '</tr>';
  912. $hh .= '<td>';
  913. $hh .= '<input name="option_stock_' . $ids . '" type="text" class="form-control option_stock option_stock_' . $ids . '" value="' . $val['stock'] . '"/>';
  914. $hh .= '</td>';
  915. $hh .= '<input name="option_id_' . $ids . '" type="hidden" class="form-control option_id option_id_' . $ids . '" value="' . $val['id'] . '"/>';
  916. $hh .= '<input name="option_ids[]" type="hidden" class="form-control option_ids option_ids_' . $ids . '" value="' . $ids . '"/>';
  917. $hh .= '<input name="option_title_' . $ids . '" type="hidden" class="form-control option_title option_title_' . $ids . '" value="' . $val['title'] . '"/>';
  918. $hh .= '<input name="option_virtual_' . $ids . '" type="hidden" class="form-control option_virtual option_virtual_' . $ids . '" value="' . $val['virtual'] . '"/>';
  919. $hh .= '<input name="option_cardprice_hi_' . $ids . '" type="hidden" class="form-control option_virtual option_cardprice_hi_' . $ids . '" value="' . $val['card_price'] . '"/>';
  920. if($is_pin == 1)
  921. $hh .= '<td><input name="option_presell_' . $ids . '" type="text" class="form-control option_presell option_presell_' . $ids . '" value="' . $val['pinprice'] . '"/></td>';
  922. $hh .= '<td><input name="option_marketprice_' . $ids . '" type="text" class="form-control option_marketprice option_marketprice_' . $ids . '" value="' . $val['marketprice'] . '"/></td>';
  923. if($item['type'] != 'integral' && $is_pin == 0 && !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 && isset($item['is_take_vipcard']) && $item['is_take_vipcard'] == 1)
  924. {
  925. $hh .= '<td><input name="option_cardprice_' . $ids . '" type="text" class="form-control option_cardprice option_cardprice_' . $ids . '" value="' . $val['card_price'] . '"/></td>';
  926. }
  927. $hh .= '<td><input name="option_productprice_' . $ids . '" type="text" class="form-control option_productprice option_productprice_' . $ids . '" " value="' . $val['productprice'] . '"/></td>';
  928. $hh .= '<td><input name="option_costprice_' . $ids . '" type="text" class="form-control option_costprice option_costprice_' . $ids . '" " value="' . $val['costprice'] . '"/></td>';
  929. $hh .= '<td><input name="option_goodssn_' . $ids . '" type="text" class="form-control option_goodssn option_goodssn_' . $ids . '" " value="' . $val['goodssn'] . '"/></td>';
  930. //$hh .= '<td><input data-name="option_productsn_' . $ids . '" type="text" class="form-control option_productsn option_productsn_' . $ids . '" " value="' . $val['productsn'] . '"/></td>';
  931. $hh .= '<td><input name="option_weight_' . $ids . '" type="text" class="form-control option_weight option_weight_' . $ids . '" " value="' . $val['weight'] . '"/></td>';
  932. $hh .= '</tr>';
  933. }
  934. ++$i;
  935. }
  936. $discounts_html .= $dd;
  937. $discounts_html .= '</table>';
  938. $isdiscount_discounts_html .= $isdd;
  939. $isdiscount_discounts_html .= '</table>';
  940. $html .= $hh;
  941. $html .= '</table>';
  942. $commission_html .= $cc;
  943. $commission_html .= '</table>';
  944. $item['html'] = $html;
  945. //allspecs //html
  946. }
  947. $good_commiss_data = M('lionfish_comshop_good_commiss')->where( array('goods_id' => $id ) )->find();
  948. //$good_commiss_data = array();
  949. if( empty($good_commiss_data) )
  950. {
  951. $good_commiss_data = array();
  952. }
  953. $item = array_merge($item, $good_commiss_data);
  954. //核销数据
  955. $item_salesroombase = M('lionfish_comshop_goods_salesroombase')->where( array('goods_id' => $id) )->find();
  956. $item_salesroombase['hx_expire_end_time'] = date('Y-m-d H:i:s',$item_salesroombase['hx_expire_end_time']);
  957. $item = array_merge($item, $item_salesroombase);
  958. //核销门店
  959. $item_salesroom = M()->query("SELECT gs.*,sr.room_name,sr.room_logo FROM " . C('DB_PREFIX') .
  960. "lionfish_comshop_goods_relative_salesroom as gs left join " . C('DB_PREFIX') ."lionfish_comshop_salesroom as sr on gs.salesroom_id=sr.id WHERE gs.goods_id=".$id." order by id asc" );
  961. foreach($item_salesroom as $k=>$v){
  962. $item_salesroom_smember = M()->query("SELECT grs.*,sm.username,m.avatar FROM " . C('DB_PREFIX') .
  963. "lionfish_comshop_goods_relative_smember as grs left join " . C('DB_PREFIX') ."lionfish_comshop_salesroom_member as sm on grs.smember_id=sm.id ".
  964. " left join " . C('DB_PREFIX') ."lionfish_comshop_member as m on sm.member_id=m.member_id ".
  965. " WHERE grs.gr_id=".$v['id']." order by id asc" );
  966. $item_salesroom[$k]['smember_list'] = $item_salesroom_smember;
  967. }
  968. $item['salesroom_list'] = $item_salesroom;
  969. return $item;
  970. }
  971. /**
  972. * @author yj 2020-08-08
  973. * @desc 获取商品规格值关联id数组
  974. * @param $goods_id
  975. * @return array
  976. */
  977. public function getGoodsOptionItemValueSpecIdsArray( $goods_id )
  978. {
  979. $option_item_value_collects = M('lionfish_comshop_goods_option_item_value')->where(array('goods_id' => $goods_id))->select();
  980. $data = array();
  981. if( !empty($option_item_value_collects) )
  982. {
  983. foreach( $option_item_value_collects as $collect )
  984. {
  985. $data[] = $collect['option_item_ids'];
  986. }
  987. }
  988. return $data;
  989. }
  990. /**
  991. * @author yj 2020-08-08
  992. * @desc 删除不在规定数组中的商品规格值关联数据
  993. * @param $option_item_value_ids_arr
  994. * @param $spec_item_value_id_arr
  995. */
  996. public function deleteGoodsOptionValueSpecUninArray($option_item_value_ids_arr,$spec_item_value_id_arr , $goods_id)
  997. {
  998. $is_delete = 0;
  999. if( !empty($option_item_value_ids_arr) )
  1000. {
  1001. foreach( $option_item_value_ids_arr as $spec )
  1002. {
  1003. if(in_array( $spec , $spec_item_value_id_arr ) )
  1004. {
  1005. $key = array_search($spec , $spec_item_value_id_arr);
  1006. if ($key !== false)
  1007. array_splice($spec_item_value_id_arr, $key, 1);
  1008. }
  1009. }
  1010. if( !empty($spec_item_value_id_arr) )
  1011. {
  1012. $is_delete = 1;
  1013. }
  1014. }else{
  1015. $is_delete = 1;
  1016. }
  1017. //如果可以删,要删除规格值 删除 规格项
  1018. if( $is_delete )
  1019. {
  1020. M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id) )->delete();
  1021. M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $goods_id) )->delete();
  1022. M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id) )->delete();
  1023. }
  1024. }
  1025. public function modify_goods($type = 'normal')
  1026. {
  1027. global $_W;
  1028. global $_GPC;
  1029. $goods_id = I('get.id');
  1030. $post_data = array();
  1031. $post_data_goods = array();
  1032. $post_data_goods['goodsname'] = I('post.goodsname');
  1033. $post_data_goods['subtitle'] = I('post.subtitle');
  1034. $post_data_goods['grounding'] = I('post.grounding');
  1035. $post_data_goods['is_index_show'] = I('post.is_index_show');
  1036. $post_data_goods['price'] = I('post.price');
  1037. $post_data_goods['productprice'] = I('post.productprice');
  1038. $post_data_goods['card_price'] = I('post.card_price');
  1039. $post_data_goods['costprice'] = I('post.costprice');
  1040. $post_data_goods['sales'] = I('post.sales');
  1041. $post_data_goods['showsales'] = I('post.showsales');
  1042. $post_data_goods['dispatchtype'] = I('post.dispatchtype');
  1043. $post_data_goods['dispatchid'] = I('post.dispatchid');
  1044. $post_data_goods['index_sort'] = I('post.index_sort','','intval');
  1045. $post_data_goods['dispatchprice'] = I('post.dispatchprice');
  1046. $post_data_goods['codes'] = I('post.codes');
  1047. $post_data_goods['weight'] = I('post.weight');
  1048. $post_data_goods['total'] = I('post.total');
  1049. $post_data_goods['hasoption'] = I('post.hasoption');
  1050. $post_data_goods['credit'] = I('post.credit');
  1051. $post_data_goods['buyagain'] = I('post.buyagain');
  1052. $post_data_goods['buyagain_condition'] = I('post.buyagain_condition');
  1053. $post_data_goods['buyagain_sale'] = I('post.buyagain_sale');
  1054. if (defined('ROLE') && ROLE == 'agenter' ) {
  1055. $supply_can_distribution_sale = D('Home/Front')->get_config_by_name('supply_can_distribution_sale');
  1056. if($supply_can_distribution_sale == 1){
  1057. $post_data_goods['is_all_sale'] = I('post.is_all_sale',0,'intval');
  1058. }
  1059. }else{
  1060. $post_data_goods['is_all_sale'] = I('post.is_all_sale',0,'intval');
  1061. }
  1062. $post_data_goods['is_seckill'] = I('post.is_seckill',0,'intval');
  1063. $post_data_goods['is_take_vipcard'] = I('post.is_take_vipcard',0,'intval');
  1064. if (defined('ROLE') && ROLE == 'agenter' ) {
  1065. $supply_edit_goods_shenhe = D('Home/Front')->get_config_by_name('supply_edit_goods_shenhe');
  1066. if( empty($supply_edit_goods_shenhe) )
  1067. {
  1068. $supply_edit_goods_shenhe = 0;
  1069. }
  1070. if($supply_edit_goods_shenhe)
  1071. {
  1072. $post_data_goods['grounding'] = 4;
  1073. }
  1074. }
  1075. M('lionfish_comshop_goods')->where(array('id' => $goods_id))->save($post_data_goods);
  1076. //find type ,modify somethings TODO...
  1077. $pin_type_arr = array(
  1078. 'pin'=>'主流团',
  1079. 'lottery'=>'抽奖团',
  1080. 'oldman'=>'老人团',
  1081. 'newman'=>'新人团',
  1082. 'commiss'=>'佣金团',
  1083. 'ladder'=>'阶梯团',
  1084. 'flash'=>'快闪团',
  1085. );
  1086. $pin_type = array_keys($pin_type_arr);
  1087. if( in_array($type, $pin_type) )
  1088. {
  1089. //插入 拼团商品表 lionfish_comshop_good_pin
  1090. $pin_data = array();
  1091. $pin_data['pinprice'] = I('post.pinprice');
  1092. $pin_data['pin_count'] = I('post.pin_count');
  1093. $pin_data['pin_hour'] = I('post.pin_hour');
  1094. $pin_data['is_commiss_tuan'] = I('post.is_commiss_tuan', 0);
  1095. $pin_data['is_zero_open'] = 0;
  1096. if($pin_data['is_commiss_tuan'] == 1)
  1097. {
  1098. $pin_data['is_zero_open'] = I('post.is_zero_open', 0);
  1099. }
  1100. $pin_data['is_newman'] = I('post.is_newman', 0);
  1101. $commiss_tuan_money1 = I('post.commiss_tuan_money1', 0);
  1102. $commiss_tuan_money2 = I('post.commiss_tuan_money2', 0);
  1103. if( isset($commiss_tuan_money1) && $commiss_tuan_money1 >0 )
  1104. {
  1105. $pin_data['commiss_type'] = 0;
  1106. $pin_data['commiss_money'] = $commiss_tuan_money1;
  1107. }else{
  1108. $pin_data['commiss_type'] = 1;
  1109. $pin_data['commiss_money'] = $commiss_tuan_money2;
  1110. }
  1111. $time_st = I('post.time');
  1112. $pin_data['begin_time'] = strtotime( $time_st['start'].':00' );
  1113. $pin_data['end_time'] = strtotime( $time_st['end'].':00' );
  1114. //拼团返利设置
  1115. $pin_data['is_pintuan_rebate'] = I('post.is_pintuan_rebate',0);
  1116. if($pin_data['is_pintuan_rebate'] == 1){
  1117. $pin_data['random_delivery_count'] = I('post.random_delivery_count',0);
  1118. $pin_data['rebate_reward'] = I('post.rebate_reward', 1);
  1119. $pin_data['reward_point'] = I('post.reward_point', 0);
  1120. $pin_data['reward_balance'] = I('post.reward_balance', 0);
  1121. }
  1122. M('lionfish_comshop_good_pin')->where( array('goods_id' => $goods_id) )->save( $pin_data );
  1123. }
  1124. $cates = I('post.cate_mult');
  1125. if( !empty($cates) )
  1126. {
  1127. //删除商品的分类
  1128. M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $goods_id) )->delete();
  1129. foreach($cates as $cate_id)
  1130. {
  1131. $post_data_category = array();
  1132. $post_data_category['cate_id'] = $cate_id;
  1133. $post_data_category['goods_id'] = $goods_id;
  1134. M('lionfish_comshop_goods_to_category')->add($post_data_category);
  1135. }
  1136. }else{
  1137. M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $goods_id) )->delete();
  1138. }
  1139. //核销begin TODO.....
  1140. $is_only_hexiao = I('post.is_only_hexiao',0);
  1141. //if($is_only_hexiao == 1){
  1142. $hx_time = time();
  1143. $item_salesroombase = M('lionfish_comshop_goods_salesroombase')->where( array('goods_id' => $goods_id) )->find();
  1144. if(!empty($item_salesroombase)){
  1145. $hx_data = array();
  1146. $hx_data['goods_id'] = $goods_id;
  1147. $hx_data['is_only_hexiao'] = $is_only_hexiao;
  1148. $hx_data['hexiao_type'] = I('post.hexiao_type',0);
  1149. $hx_data['hx_one_goods_time'] = I('post.hx_one_goods_time',0);
  1150. $hx_data['hx_expire_type'] = I('post.hx_expire_type',0);
  1151. $hx_data['hx_expire_day'] = I('post.hx_expire_day');
  1152. $hx_data['hx_expire_begin_time'] = $item_salesroombase['hx_expire_begin_time'];
  1153. if($hx_data['hx_expire_type'] == 1){
  1154. $hx_data['hx_expire_end_time'] = strtotime(I('post.hx_expire_end_time'));
  1155. }else{
  1156. if(empty($hx_data['hx_expire_day'])){
  1157. $hx_data['hx_expire_day'] = 90;
  1158. }
  1159. $hx_data['hx_expire_end_time'] = $item_salesroombase['hx_expire_begin_time']+$hx_data['hx_expire_day']*24*60*60;
  1160. }
  1161. $hx_data['hx_assign_salesroom'] = I('post.hx_assign_salesroom',0);
  1162. $hx_data['hx_auto_off'] = I('post.hx_auto_off',0);
  1163. $hx_data['hx_auto_off_time'] = I('post.hx_auto_off_time',0);
  1164. M('lionfish_comshop_goods_salesroombase')->where( array('id' => $item_salesroombase['id']) )->save($hx_data);
  1165. //删除关联核销员
  1166. $salesroom_list = M('lionfish_comshop_goods_relative_salesroom')->where( array('goods_id' => $goods_id) )->select();
  1167. foreach($salesroom_list as $sk=>$sv){
  1168. M('lionfish_comshop_goods_relative_smember')->where( array('gr_id' => $sv['id']) )->delete();
  1169. }
  1170. //删除关联门店
  1171. M('lionfish_comshop_goods_relative_salesroom')->where( array('goods_id' => $goods_id) )->delete();
  1172. if($hx_data['hx_assign_salesroom'] == 1){//指定门店
  1173. $goods_room_ids = I('post.goods_room_ids','');
  1174. $goods_is_hx_member = I('post.goods_is_hx_member','');
  1175. $goods_room_smember = I('post.goods_room_smember','');
  1176. if(!empty($goods_room_ids)){
  1177. $goods_room_array = explode(',',$goods_room_ids);
  1178. foreach($goods_room_array as $grv){
  1179. $goods_room_smember_ids = $goods_room_smember[$grv];
  1180. $goods_room_data = array();
  1181. $goods_room_data['salesroom_id'] = $grv;
  1182. $goods_room_data['goods_id'] = $goods_id;
  1183. $goods_room_data['is_hx_member'] = $goods_is_hx_member[$grv];
  1184. if($goods_is_hx_member[$grv] == 1 && empty($goods_room_smember_ids)){
  1185. $goods_room_data['is_hx_member'] = 0;
  1186. }
  1187. $goods_room_data['addtime'] = $hx_time;
  1188. $gr_id = M('lionfish_comshop_goods_relative_salesroom')->add($goods_room_data);
  1189. if($gr_id !== false){
  1190. $goods_room_smember_ids = $goods_room_smember[$grv];
  1191. if($goods_is_hx_member[$grv] == 1 && !empty($goods_room_smember_ids)){
  1192. $smember_ids = explode(',',$goods_room_smember_ids);
  1193. foreach($smember_ids as $sv){
  1194. $room_smember_data = array();
  1195. $room_smember_data['salesroom_id'] = $grv;
  1196. $room_smember_data['gr_id'] = $gr_id;
  1197. $room_smember_data['smember_id'] = $sv;
  1198. $room_smember_data['addtime'] = $hx_time;
  1199. M('lionfish_comshop_goods_relative_smember')->add($room_smember_data);
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }else{
  1207. $hx_data = array();
  1208. $hx_time = time();
  1209. $hx_data['goods_id'] = $goods_id;
  1210. $hx_data['is_only_hexiao'] = $is_only_hexiao;
  1211. $hx_data['hexiao_type'] = I('post.hexiao_type',0);
  1212. $hx_data['hx_one_goods_time'] = I('post.hx_one_goods_time',0);
  1213. $hx_data['hx_expire_type'] = I('post.hx_expire_type',0);
  1214. $hx_data['hx_expire_day'] = I('post.hx_expire_day');
  1215. $hx_data['hx_expire_begin_time'] = $hx_time;
  1216. if($hx_data['hx_expire_type'] == 1){
  1217. $hx_data['hx_expire_end_time'] = strtotime(I('post.hx_expire_end_time'));
  1218. }else{
  1219. if(empty($hx_data['hx_expire_day'])){
  1220. $hx_data['hx_expire_day'] = 90;
  1221. }
  1222. $hx_data['hx_expire_end_time'] = $hx_time+$hx_data['hx_expire_day']*24*60*60;
  1223. }
  1224. $hx_data['hx_assign_salesroom'] = I('post.hx_assign_salesroom',0);
  1225. $hx_data['addtime'] = $hx_time;
  1226. M('lionfish_comshop_goods_salesroombase')->add($hx_data);
  1227. if($hx_data['hx_assign_salesroom'] == 1){//指定门店
  1228. $goods_room_ids = I('post.goods_room_ids','');
  1229. $goods_is_hx_member = I('post.goods_is_hx_member','');
  1230. $goods_room_smember = I('post.goods_room_smember','');
  1231. if(!empty($goods_room_ids)){
  1232. $goods_room_array = explode(',',$goods_room_ids);
  1233. foreach($goods_room_array as $grv){
  1234. $goods_room_smember_ids = $goods_room_smember[$grv];
  1235. $goods_room_data = array();
  1236. $goods_room_data['salesroom_id'] = $grv;
  1237. $goods_room_data['goods_id'] = $goods_id;
  1238. $goods_room_data['is_hx_member'] = $goods_is_hx_member[$grv];
  1239. if($goods_is_hx_member[$grv] == 1 && empty($goods_room_smember_ids)){
  1240. $goods_room_data['is_hx_member'] = 0;
  1241. }
  1242. $goods_room_data['addtime'] = $hx_time;
  1243. $gr_id = M('lionfish_comshop_goods_relative_salesroom')->add($goods_room_data);
  1244. if($gr_id !== false){
  1245. $goods_room_smember_ids = $goods_room_smember[$grv];
  1246. if($goods_is_hx_member[$grv] == 1 && !empty($goods_room_smember_ids)){
  1247. $smember_ids = explode(',',$goods_room_smember_ids);
  1248. foreach($smember_ids as $sv){
  1249. $room_smember_data = array();
  1250. $room_smember_data['salesroom_id'] = $grv;
  1251. $room_smember_data['gr_id'] = $gr_id;
  1252. $room_smember_data['smember_id'] = $sv;
  1253. $room_smember_data['addtime'] = $hx_time;
  1254. M('lionfish_comshop_goods_relative_smember')->add($room_smember_data);
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. }
  1261. }
  1262. //}
  1263. //核销end
  1264. //lionfish_comshop_goods_images
  1265. $thumbs = I('post.thumbs');
  1266. if( !empty($thumbs) )
  1267. {
  1268. M('lionfish_comshop_goods_images')->where( array('goods_id' => $goods_id) )->delete();
  1269. foreach($thumbs as $thumbs)
  1270. {
  1271. $post_data_thumbs = array();
  1272. $post_data_thumbs['goods_id'] = $goods_id;
  1273. $post_data_thumbs['image'] = save_media($thumbs);
  1274. $post_data_thumbs['thumb'] = save_media( resize($thumbs,100,100));
  1275. M('lionfish_comshop_goods_images')->add($post_data_thumbs);
  1276. }
  1277. }
  1278. //lionfish_comshop_good_common
  1279. $post_data_common = array();
  1280. $post_data_common['quality'] = I('post.quality');
  1281. $post_data_common['seven'] = I('post.seven');
  1282. $post_data_common['repair'] = I('post.repair');
  1283. $labelname = I('post.labelname');
  1284. $post_data_common['labelname'] = serialize($labelname);
  1285. $post_data_common['share_title'] = I('post.share_title');
  1286. $post_data_common['share_description'] = I('post.share_description');
  1287. $post_data_common['content'] = I('post.content','','htmlspecialchars');
  1288. $post_data_common['pick_up_type'] = I('post.pick_up_type');
  1289. $post_data_common['pick_up_modify'] = I('post.pick_up_modify');
  1290. $post_data_common['one_limit_count'] = I('post.one_limit_count');
  1291. $post_data_common['oneday_limit_count'] = I('post.oneday_limit_count');
  1292. $post_data_common['total_limit_count'] = I('post.total_limit_count');
  1293. $post_data_common['goods_start_count'] = I('post.goods_start_count');
  1294. $community_head_commission = I('post.community_head_commission');
  1295. $is_community_head_commission = I('post.is_community_head_commission');
  1296. $post_data_common['is_community_head_commission'] = $is_community_head_commission;
  1297. $post_data_common['is_show_arrive'] = I('post.is_show_arrive');
  1298. $post_data_common['diy_arrive_switch'] = I('post.diy_arrive_switch');
  1299. $post_data_common['diy_arrive_details'] = I('post.diy_arrive_details');
  1300. $post_data_common['is_new_buy'] = I('post.is_new_buy');
  1301. $post_data_common['is_spike_buy'] = I('post.is_spike_buy');
  1302. if(isset($community_head_commission))
  1303. {
  1304. $post_data_common['community_head_commission'] = I('post.community_head_commission');
  1305. }
  1306. if (defined('ROLE') && ROLE == 'agenter' )
  1307. {
  1308. $supply_can_goods_sendscore = D('Home/Front')->get_config_by_name('supply_can_goods_sendscore');
  1309. if($supply_can_goods_sendscore == 1){
  1310. $post_data_common['is_modify_sendscore'] = I('post.is_modify_sendscore',0);
  1311. $post_data_common['send_socre'] = I('post.send_socre');
  1312. }
  1313. }else{
  1314. $post_data_common['is_modify_sendscore'] = I('post.is_modify_sendscore',0);
  1315. $post_data_common['send_socre'] = I('post.send_socre');
  1316. }
  1317. $post_data_common['is_mb_level_buy'] = I('post.is_mb_level_buy',1);
  1318. if (defined('ROLE') && ROLE == 'agenter' )
  1319. {
  1320. $supper_info = get_agent_logininfo();
  1321. $post_data_common['supply_id'] = $supper_info['id'];
  1322. }else{
  1323. $post_data_common['supply_id'] = I('post.supply_id');
  1324. }
  1325. $time = I('post.time');
  1326. $post_data_common['begin_time'] = strtotime( $time['start'] );
  1327. $post_data_common['end_time'] = strtotime( $time['end'] );
  1328. $big_img =I('post.big_img');
  1329. $goods_share_image =I('post.goods_share_image');
  1330. $post_data_common['big_img'] = save_media($big_img);
  1331. $post_data_common['goods_share_image'] = save_media($goods_share_image);
  1332. $post_data_common['video'] = save_media(I('post.video'));
  1333. $post_data_common['video'] = $this->check_douyin_video($post_data_common['video']);
  1334. $post_data_common['print_sub_title'] = I('post.print_sub_title');
  1335. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1336. if( empty($is_open_fullreduction) )
  1337. {
  1338. $post_data_common['is_take_fullreduction'] = 1;
  1339. }else if( $is_open_fullreduction ==0 )
  1340. {
  1341. }else if($is_open_fullreduction ==1){
  1342. $post_data_common['is_take_fullreduction'] = I('post.is_take_fullreduction' ,1);
  1343. }
  1344. if($post_data_common['is_take_fullreduction'] == 1 && $post_data_common['supply_id'] > 0)
  1345. {
  1346. $supply_info = M('lionfish_comshop_supply')->field('type')->where( array('id' => $post_data_common['supply_id'] ) )->find();
  1347. if( !empty($supply_info) && $supply_info['type'] == 1 )
  1348. {
  1349. $post_data_common['is_take_fullreduction'] = 0;
  1350. }
  1351. }
  1352. //begin
  1353. if (defined('ROLE') && ROLE == 'agenter' )
  1354. {
  1355. $is_modify_head_commission = I('post.is_modify_head_commission','0','intval');
  1356. if( isset($is_modify_head_commission) )
  1357. {
  1358. $post_data_common['is_modify_head_commission'] = $is_modify_head_commission;
  1359. if($post_data_common['is_modify_head_commission'] == 1)
  1360. {
  1361. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1362. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1363. $default_comunity_money = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1364. $list_default = array(
  1365. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1366. );
  1367. $community_head_level = array_merge($list_default, $community_head_level);
  1368. $community_head_commission_modify = array();
  1369. foreach($community_head_level as $kk => $vv)
  1370. {
  1371. $community_head_commission_modify['head_level'.$vv['id']] = I('post.head_level'.$vv['id']);
  1372. }
  1373. if( !isset($is_community_head_commission)){
  1374. $post_data_common['community_head_commission'] = $community_head_commission_modify['head_level0'];
  1375. }
  1376. $post_data_common['community_head_commission_modify'] = serialize($community_head_commission_modify);
  1377. }
  1378. }else{
  1379. $post_data_common['is_modify_head_commission'] = 0;
  1380. }
  1381. }else{
  1382. $is_modify_head_commission = I('post.is_modify_head_commission','0','intval');
  1383. if( isset($is_modify_head_commission) )
  1384. {
  1385. $post_data_common['is_modify_head_commission'] = $is_modify_head_commission;
  1386. if($post_data_common['is_modify_head_commission'] == 1)
  1387. {
  1388. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1389. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1390. $default_comunity_money = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1391. $list_default = array(
  1392. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1393. );
  1394. $community_head_level = array_merge($list_default, $community_head_level);
  1395. $community_head_commission_modify = array();
  1396. foreach($community_head_level as $kk => $vv)
  1397. {
  1398. $community_head_commission_modify['head_level'.$vv['id']] = I('post.head_level'.$vv['id']);
  1399. }
  1400. if( !isset($is_community_head_commission)){
  1401. $post_data_common['community_head_commission'] = $community_head_commission_modify['head_level0'];
  1402. }
  1403. $post_data_common['community_head_commission_modify'] = serialize($community_head_commission_modify);
  1404. }
  1405. }else{
  1406. $post_data_common['is_modify_head_commission'] = 0;
  1407. }
  1408. }
  1409. //end
  1410. $post_data_common['is_only_express'] = I('post.is_only_express',0);
  1411. $post_data_common['is_only_hexiao'] = $is_only_hexiao;
  1412. $post_data_common['is_limit_levelunbuy'] = I('post.is_limit_levelunbuy',0);
  1413. $post_data_common['is_limit_vipmember_buy'] = I('post.is_limit_vipmember_buy',0);
  1414. $post_data_common['packing_free'] = I('post.packing_free',0);
  1415. if( $post_data_common['is_only_express'] == 1 )
  1416. {
  1417. $post_data_common['is_only_distribution'] = 0;
  1418. }else{
  1419. $is_only_distribution = I('post.is_only_distribution');
  1420. $post_data_common['is_only_distribution'] = $is_only_distribution;
  1421. }
  1422. $relative_goods_list = array();
  1423. $limit_goods_list = I('post.limit_goods_list');
  1424. if( isset($limit_goods_list) && !empty($limit_goods_list) )
  1425. {
  1426. $limit_goods_list = explode(',', $limit_goods_list);
  1427. foreach($limit_goods_list as $tp_val )
  1428. {
  1429. if($tp_val != $goods_id)
  1430. {
  1431. $relative_goods_list[] = $tp_val;
  1432. }
  1433. }
  1434. }
  1435. $post_data_common['relative_goods_list'] = serialize($relative_goods_list);
  1436. $post_data_common['has_mb_level_buy'] = I('post.has_mb_level_buy',0,'intval');
  1437. $level_id_list = I('post.level_id');
  1438. $discount_list = I('post.discount');
  1439. $mb_level_buy_list = array();
  1440. if(isset($level_id_list) && !empty($level_id_list)){
  1441. for($i = 0;$i < count($level_id_list);$i++){
  1442. $level_list = array();
  1443. $level_list['level_id'] = $level_id_list[$i];
  1444. if(!is_numeric($discount_list[$i])){
  1445. $level_list['discount'] = '';
  1446. }else{
  1447. if($discount_list[$i] < 0 && $discount_list[$i] > 100){
  1448. $level_list['discount'] = 0;
  1449. }else{
  1450. $level_list['discount'] = $discount_list[$i];
  1451. }
  1452. }
  1453. $mb_level_buy_list[] = $level_list;
  1454. }
  1455. }
  1456. $post_data_common['mb_level_buy_list'] = serialize($mb_level_buy_list);
  1457. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save($post_data_common);
  1458. //M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id) )->delete();
  1459. //M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $goods_id) )->delete();
  1460. //M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id) )->delete();
  1461. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  1462. $hasoption = I('post.hasoption',0,'intval');
  1463. //规格
  1464. if( intval($hasoption) == 1 )
  1465. {
  1466. $save_goods_option_arr = array();//有用的goods_option_id
  1467. $save_goods_option_item_arr = array();// 有用的 goods_option_item
  1468. $save_goods_option_item_value_arr = array();// 有用的 goods_option_item_value
  1469. $mult_option_item_dan_key = array();
  1470. $replace_option_item_id_arr = array();//需要更替的option_item_id
  1471. $spec_id = I('post.spec_id');
  1472. $option_ids_arr = I('post.option_ids');
  1473. //begin 换算多规格算法
  1474. $option_item_value_ids_arr = $this->getGoodsOptionItemValueSpecIdsArray( $goods_id );
  1475. $this->deleteGoodsOptionValueSpecUninArray( $option_item_value_ids_arr, $option_ids_arr , $goods_id );
  1476. //end 换算多规格算法
  1477. if( !empty($spec_id) )
  1478. {
  1479. $option_order = 1;
  1480. $spec_title_arr = I('post.spec_title');
  1481. foreach($spec_id as $spec_id)
  1482. {
  1483. //规格标题
  1484. $cur_spec_title = $spec_title_arr[$spec_id];
  1485. $goods_option_data = array();
  1486. $goods_option['goods_id'] = $goods_id;
  1487. $goods_option['title'] = $cur_spec_title;
  1488. $goods_option['displayorder'] = $option_order;
  1489. //查找是否存在这个规格
  1490. $ck_goods_option = M('lionfish_comshop_goods_option')->where( array('id' => $spec_id ) )->find();
  1491. if( !empty($ck_goods_option) )
  1492. {
  1493. M('lionfish_comshop_goods_option')->where( array('id' => $spec_id ) )->save($goods_option);
  1494. $option_id = $spec_id;
  1495. }else{
  1496. $option_id = M('lionfish_comshop_goods_option')->add($goods_option);
  1497. }
  1498. $save_goods_option_arr[] = $option_id;
  1499. $spec_item_title_arr = I('post.spec_item_title_'.$spec_id);
  1500. if(!empty($spec_item_title_arr))
  1501. {
  1502. $item_sort = 1;
  1503. $i = 0;
  1504. $j = 0;
  1505. foreach($spec_item_title_arr as $key =>$item_title)
  1506. {
  1507. $spec_item_thumb_arr = I('post.spec_item_thumb_'.$spec_id);
  1508. $goods_option_item_data = array();
  1509. $goods_option_item_data['goods_id'] = $goods_id;
  1510. $goods_option_item_data['goods_option_id'] = $option_id;
  1511. $goods_option_item_data['title'] = $item_title;
  1512. $goods_option_item_data['thumb'] = $spec_item_thumb_arr[$key];
  1513. $goods_option_item_data['displayorder'] = $item_sort;
  1514. //$option_item_id = M('lionfish_comshop_goods_option_item')->add($goods_option_item_data);
  1515. $spec_item_id_kk = I('post.spec_item_id_'.$spec_id);
  1516. $option_item_id = $spec_item_id_kk[$key];
  1517. $ck_option_item = M('lionfish_comshop_goods_option_item')->where( array('id' => $option_item_id ) )->find();
  1518. if( !empty($ck_option_item) )
  1519. {
  1520. M('lionfish_comshop_goods_option_item')->where( array('id' => $option_item_id ) )->save( $goods_option_item_data );
  1521. }else{
  1522. $new_option_item_id = M('lionfish_comshop_goods_option_item')->add( $goods_option_item_data );
  1523. $replace_option_item_id_arr[$option_item_id] = $new_option_item_id;
  1524. $option_item_id = $new_option_item_id;
  1525. }
  1526. $save_goods_option_item_arr[] = $option_item_id;
  1527. //从小到大的排序
  1528. $mult_option_item_dan_key[ $spec_item_id_kk[$key] ] = $option_item_id;
  1529. $item_sort++;
  1530. $i++;
  1531. }
  1532. }else{
  1533. M('lionfish_comshop_goods_option')->where( array('id' => $id) )->delete();
  1534. }
  1535. $option_order++;
  1536. }
  1537. //开始清理无效的 规格 规格项
  1538. if( empty($save_goods_option_arr) )
  1539. {
  1540. M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id ) )->delete();
  1541. }else{
  1542. $save_goods_option_str = implode(',', $save_goods_option_arr );
  1543. M('lionfish_comshop_goods_option')->where( 'goods_id=' . $goods_id.' and id not in('.$save_goods_option_str.')' )->delete();
  1544. }
  1545. if( empty($save_goods_option_item_arr) )
  1546. {
  1547. M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $goods_id ) )->delete();
  1548. }else{
  1549. $save_goods_option_item_str = implode(',', $save_goods_option_item_arr );
  1550. M('lionfish_comshop_goods_option_item')->where('goods_id=' . $goods_id.' and id not in('.$save_goods_option_item_str.')')->delete();
  1551. }
  1552. }
  1553. /**
  1554. $option_ids_arr2 = $_REQUEST['option_ids'];
  1555. var_dump($option_ids_arr);
  1556. echo '<br/>';
  1557. var_dump($option_ids_arr2);
  1558. die();
  1559. * **/
  1560. /**
  1561. array(9) {
  1562. [0]=>
  1563. string(9) "1022_1029"
  1564. [1]=>
  1565. string(9) "1022_1034"
  1566. [2]=>
  1567. string(9) "1022_1035"
  1568. [3]=>
  1569. string(9) "1023_1029"
  1570. [4]=>
  1571. string(9) "1023_1034"
  1572. [5]=>
  1573. string(9) "1023_1035"
  1574. [6]=>
  1575. string(37) "L7uW7b72wycNYcw7r7CimqwC77Nyywui _1029"
  1576. [7]=>
  1577. string(37) "L7uW7b72wycNYcw7r7CimqwC77Nyywui_1034"
  1578. [8]=>
  1579. string(37) "L7uW7b72wycNYcw7r7CimqwC77Nyywui_1035"
  1580. }
  1581. array(1) {
  1582. ["L7uW7b72wycNYcw7r7CimqwC77Nyywui"]=>
  1583. string(4) "1037"
  1584. }
  1585. **/
  1586. $mdata = I('post.');
  1587. $total = 0;
  1588. foreach($option_ids_arr as $val)
  1589. {
  1590. $option_item_ids = '';
  1591. $option_item_ids_arr = array();
  1592. $key_items = explode('_', $val);
  1593. $new_val = array();
  1594. foreach($key_items as $vv)
  1595. {
  1596. if( isset($replace_option_item_id_arr[$vv]) )
  1597. {
  1598. $option_item_ids_arr[] = $replace_option_item_id_arr[$vv];
  1599. }else{
  1600. $option_item_ids_arr[] = $mult_option_item_dan_key[$vv];
  1601. }
  1602. $new_val[] = $vv;
  1603. }
  1604. //asort($new_val);
  1605. //$val = implode('_', $new_val);
  1606. asort($option_item_ids_arr);
  1607. $option_item_ids = implode('_', $option_item_ids_arr);
  1608. $snailfish_goods_option_item_value_data = array();
  1609. $snailfish_goods_option_item_value_data['goods_id'] = $goods_id;
  1610. $snailfish_goods_option_item_value_data['option_item_ids'] = $option_item_ids;
  1611. $productprice = I('post.option_productprice_'.$val);
  1612. $snailfish_goods_option_item_value_data['productprice'] = $productprice;
  1613. $pinprice = I('post.option_presell_'.$val);
  1614. $snailfish_goods_option_item_value_data['pinprice'] = $pinprice;
  1615. $marketprice = I('post.option_marketprice_'.$val);
  1616. $snailfish_goods_option_item_value_data['marketprice'] = $marketprice;
  1617. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  1618. {
  1619. $card_price = I('post.option_cardprice_'.$val);
  1620. $snailfish_goods_option_item_value_data['card_price'] = $card_price;
  1621. }
  1622. $stock = I('post.option_stock_'.$val);
  1623. $snailfish_goods_option_item_value_data['stock'] = $stock;
  1624. $costprice = I('post.option_costprice_'.$val);
  1625. $snailfish_goods_option_item_value_data['costprice'] = $costprice;
  1626. $goodssn = I('post.option_goodssn_'.$val);
  1627. $snailfish_goods_option_item_value_data['goodssn'] = $goodssn;
  1628. $weight = I('post.option_weight_'.$val);
  1629. $snailfish_goods_option_item_value_data['weight'] = $weight;
  1630. $title = I('post.option_title_'.$val);
  1631. $snailfish_goods_option_item_value_data['title'] = $title;
  1632. $total += $snailfish_goods_option_item_value_data['stock'];
  1633. //option_id_1979 TODO
  1634. $option_item_value_id = I('post.option_id_'.$val);
  1635. $ck_option_item_value = M('lionfish_comshop_goods_option_item_value')->where( array('id' => $option_item_value_id ) )->find();
  1636. if( !empty($ck_option_item_value) )
  1637. {
  1638. M('lionfish_comshop_goods_option_item_value')->where( array('id' => $option_item_value_id ) )->save( $snailfish_goods_option_item_value_data );
  1639. }else{
  1640. $option_item_value_id = M('lionfish_comshop_goods_option_item_value')->add( $snailfish_goods_option_item_value_data );
  1641. }
  1642. $save_goods_option_item_value_arr[] = $option_item_value_id;
  1643. //M('lionfish_comshop_goods_option_item_value')->add($snailfish_goods_option_item_value_data);
  1644. }
  1645. if( empty($save_goods_option_item_value_arr) )
  1646. {
  1647. M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id ) )->delete();
  1648. }else{
  1649. $save_goods_option_item_value_str = implode(',', $save_goods_option_item_value_arr );
  1650. M('lionfish_comshop_goods_option_item_value')->where('goods_id=' . $goods_id.' and id not in('.$save_goods_option_item_value_str.')' )->delete();
  1651. }
  1652. //更新库存 total
  1653. $up_goods_data = array();
  1654. $up_goods_data['total'] = $total;
  1655. M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->save( $up_goods_data );
  1656. }
  1657. else{
  1658. M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id ) )->delete();
  1659. M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $goods_id ) )->delete();
  1660. M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id ) )->delete();
  1661. }
  1662. if( !empty($save_goods_option_arr) )
  1663. {
  1664. foreach( $save_goods_option_arr as $k_option_id )
  1665. {
  1666. $tp_item_val = M('lionfish_comshop_goods_option_item')->where( array('goods_option_id' => $k_option_id ) )->find();
  1667. if( empty($tp_item_val) )
  1668. {
  1669. M('lionfish_comshop_goods_option')->where( array('id' => $k_option_id ) )->delete();
  1670. }
  1671. }
  1672. }
  1673. //stock hascommission
  1674. //规格插入
  1675. //lionfish_comshop_good_commiss
  1676. M('lionfish_comshop_good_commiss')->where( array('goods_id' => $goods_id ) )->delete();
  1677. $post_data_commiss = array();
  1678. $post_data_commiss['goods_id'] = $goods_id;
  1679. $post_data_commiss['nocommission'] = I('post.nocommission',0,'intval');
  1680. $post_data_commiss['hascommission'] = I('post.hascommission',0,'intval');
  1681. $post_data_commiss['commission_type'] = I('post.commission_type',0,'intval');
  1682. $post_data_commiss['commission1_rate'] = I('post.commission1_rate');
  1683. $post_data_commiss['commission1_pay'] = I('post.commission1_pay');
  1684. $post_data_commiss['commission2_rate'] = I('post.commission2_rate');
  1685. $post_data_commiss['commission2_pay'] = I('post.commission2_pay');
  1686. $post_data_commiss['commission3_rate'] = I('post.commission3_rate');
  1687. $post_data_commiss['commission3_pay'] = I('post.commission3_pay');
  1688. M('lionfish_comshop_good_commiss')->add( $post_data_commiss );
  1689. //变更预售商品begin
  1690. $new_goods_type_info = M('lionfish_comshop_goods')->field('type')->where( ['id' => $goods_id ] )->find();
  1691. if($new_goods_type_info['type'] == 'presale' )
  1692. {
  1693. D('Seller/GoodsPresale')->modifyGoodsPresale( $goods_id );
  1694. }
  1695. //end
  1696. //虚拟卡密
  1697. if( isset($_POST['is_virtualcard_goods']) && $_POST['is_virtualcard_goods'] == 1 )
  1698. {
  1699. D('Seller/VirtualCard')->modifyGoodsVirtualCard( $goods_id );
  1700. }
  1701. D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  1702. }
  1703. }
  1704. ?>