GoodsModel.class.php 80 KB

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