PingoodsModel.class.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  1. <?php
  2. namespace Home\Model;
  3. /**
  4. * 拼团模型模型
  5. * @author fish
  6. *
  7. */
  8. class PingoodsModel {
  9. public function get_community_index_goods($fields='*', $where='1=1',$offset=0,$perpage=10,$order='g.istop DESC, g.settoptime DESC,g.index_sort desc,g.id desc ' )
  10. {
  11. $sql_pingoods = "select {$fields} from "
  12. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc
  13. where {$where} and g.id=gc.goods_id order by {$order} limit {$offset},{$perpage} ";
  14. $list_pingoods = M()->query($sql_pingoods);
  15. return $list_pingoods;
  16. }
  17. public function get_new_community_index_goods($head_id=0,$gid='', $fields='*', $where='1=1',$offset=0,$perpage=10,$order='g.istop DESC, g.settoptime DESC,g.index_sort desc,g.id desc ')
  18. {
  19. $inner_join ="";
  20. if( $head_id > 0 )
  21. {
  22. $where .= " and (g.is_all_sale = 1 or g.id in (SELECT goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods where head_id = {$head_id}) ) ";
  23. }
  24. if( !empty($gid) )
  25. {
  26. $gd_cate_sql = " select goods_id from ".C('DB_PREFIX')."lionfish_comshop_goods_to_category where cate_id in ({$gid}) ";
  27. $cate_all = M()->query($gd_cate_sql );
  28. $cate_goods_ids = array();
  29. if( !empty($cate_all) )
  30. {
  31. foreach($cate_all as $val)
  32. {
  33. $cate_goods_ids[] = $val['goods_id'];
  34. }
  35. $cate_goods_str = implode(',', $cate_goods_ids);
  36. $where .= " and g.id in ({$cate_goods_str}) ";
  37. }else{
  38. $where .= " and g.id in (0) ";
  39. }
  40. }
  41. $sql_pingoods = "select {$fields} from "
  42. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc {$inner_join}
  43. where {$where} and g.id=gc.goods_id order by {$order} limit {$offset},{$perpage} ";
  44. $list_pingoods = M()->query($sql_pingoods);
  45. return $list_pingoods;
  46. }
  47. //begin index_share_qrcode
  48. /**
  49. 分销商海报
  50. **/
  51. public function get_commission_index_share_image($community_id,$wepro_qrcode,$avatar,$nickname)
  52. {
  53. $send_path = "Uploads/image/".date('Y-m-d')."/haibao_goods/";
  54. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  55. RecursiveMkdir($image_dir);
  56. $bg_img = ROOT_PATH."/static/images/index_share_bg.jpg";
  57. //index_share_qrcode_bg
  58. $index_share_qrcode_bg = D('Home/Front')->get_config_by_name('distribution_img_src');
  59. if( !empty($index_share_qrcode_bg) )
  60. {
  61. $bg_img = ROOT_PATH.'Uploads/image/' . $index_share_qrcode_bg;
  62. }
  63. $dst = imagecreatefromstring(file_get_contents($bg_img));
  64. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  65. $ttf_path = ROOT_PATH."/static/fonts/simhei.ttf";
  66. $msyh_path = ROOT_PATH."/static/fonts/msyh.ttf";
  67. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  68. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  69. //打上文字
  70. $black = imagecolorallocate($dst, 20,20,20);//黑色
  71. $a1a1a1 = imagecolorallocate($dst, 26,26,26);//黑色
  72. $red = imagecolorallocate($dst, 237, 48, 43); //红色 201 55 49
  73. $huise = imagecolorallocate($dst, 159, 159, 159); //灰色 159 159 159
  74. $fense = imagecolorallocate($dst, 248, 136, 161); //粉色 248 136 161
  75. $gray1 = imagecolorallocate($dst, 51, 51, 51); //#333 51, 51, 51
  76. $gray2 = imagecolorallocate($dst, 102, 102, 6); //#666 102, 102, 6
  77. $gray3 = imagecolorallocate($dst, 153, 153, 153); //#999 153, 153, 153
  78. $gray4 = imagecolorallocate($dst, 116, 116, 116); //#999 116, 116, 116
  79. $red_2 = imagecolorallocate($dst, 223, 21, 21); //#999 223, 21, 21
  80. $chengse = imagecolorallocate($dst, 252, 74, 74); //#999
  81. $distribution_username_left = D('Home/Front')->get_config_by_name('distribution_username_left');
  82. $distribution_username_top = D('Home/Front')->get_config_by_name('distribution_username_top');
  83. $distribution_username_left = empty($distribution_username_left) ? 0: $distribution_username_left * 2;
  84. $distribution_username_top = empty($distribution_username_top) ? 0: $distribution_username_top * 2 ;
  85. $avatar = 'Uploads/image/'.$avatar;
  86. $commiss_nickname_rgb = D('Home/Front')->get_config_by_name('commiss_nickname_rgb');
  87. $rgb_arr = array('r' => 248,'g' => 136,'b' => 161);
  88. if( !empty($commiss_nickname_rgb) )
  89. {
  90. $rgb_arr = $this->hex2rgb($avatar_rgb);
  91. }
  92. $col = imagecolorallocate($dst,$rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b']);
  93. //$col = imagecolorallocate($dst,248, 136, 161);
  94. imagefttext($dst, 20, 0, $distribution_username_left, $distribution_username_top, $col, $pingfang_med_path, $nickname );
  95. list($avatar_img_img_w, $avatar_img_img_h, $avatar_img_img_type) = getimagesize(ROOT_PATH.$avatar);
  96. $avatar_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$avatar));
  97. if (imageistruecolor($avatar_img_src))
  98. imagetruecolortopalette($avatar_img_src, false, 65535);
  99. $distribution_avatar_left = D('Home/Front')->get_config_by_name('distribution_avatar_left');
  100. $distribution_avatar_top = D('Home/Front')->get_config_by_name('distribution_avatar_top');
  101. if( empty($distribution_avatar_left) )
  102. {
  103. $distribution_avatar_left = 0;
  104. }else{
  105. $distribution_avatar_left = $distribution_avatar_left * 2;
  106. }
  107. if( empty($distribution_avatar_top) )
  108. {
  109. $distribution_avatar_top = 0;
  110. }else{
  111. $distribution_avatar_top = $distribution_avatar_top * 2;
  112. }
  113. imagecopy($dst, $avatar_img_src, $distribution_avatar_left, $distribution_avatar_top, 0, 0, $avatar_img_img_w, $avatar_img_img_h);
  114. //wepro_qrcode
  115. $distribution_qrcodes_left = D('Home/Front')->get_config_by_name('distribution_qrcodes_left');
  116. $distribution_qrcodes_top = D('Home/Front')->get_config_by_name('distribution_qrcodes_top');
  117. if( empty($distribution_qrcodes_left) )
  118. {
  119. $distribution_qrcodes_left = 0;
  120. }else{
  121. $distribution_qrcodes_left = $distribution_qrcodes_left * 2;
  122. }
  123. if( empty($distribution_qrcodes_top) )
  124. {
  125. $distribution_qrcodes_top = 0;
  126. }else{
  127. $distribution_qrcodes_top = $distribution_qrcodes_top * 2;
  128. }
  129. $thumb_goods_img = $wepro_qrcode;
  130. $wepro_qrcode_new = str_replace('Uploads/image/','', $thumb_goods_img);
  131. $thumb_goods_img = resize($wepro_qrcode_new,180,180);
  132. list($thumb_goods_img_w, $thumb_goods_img_h, $thumb_goods_img_type) = getimagesize(ROOT_PATH.$thumb_goods_img);
  133. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  134. $thumb_goods_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  135. if (imageistruecolor($thumb_goods_img_src))
  136. imagetruecolortopalette($thumb_goods_img_src, false, 65535);
  137. imagecopy($dst, $goods_src, $distribution_qrcodes_left, $distribution_qrcodes_top, 0, 0, $thumb_goods_img_w, $thumb_goods_img_h);
  138. /**
  139. **/
  140. $send_path = "Uploads/image/".date('Y-m-d')."/haibao_goods/";
  141. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  142. RecursiveMkdir($image_dir);
  143. $last_img = $image_dir;
  144. $last_img_name = "last_index_".md5( time().$community_id.$wepro_qrcode.mt_rand(1,999)).'';
  145. switch ($dst_type) {
  146. case 1://GIF
  147. $last_img_name .= '.gif';
  148. //header('Content-Type: image/gif');
  149. imagegif($dst, $last_img.$last_img_name);
  150. break;
  151. case 2://JPG
  152. $last_img_name .= '.jpg';
  153. //header('Content-Type: image/jpeg');
  154. imagejpeg($dst, $last_img.$last_img_name);
  155. break;
  156. case 3://PNG
  157. $last_img_name .= '.png';
  158. //header('Content-Type: image/png');
  159. imagepng($dst, $last_img.$last_img_name);
  160. break;
  161. default:
  162. break;
  163. }
  164. imagedestroy($dst);
  165. $fullname = ROOT_PATH.$send_path.$last_img_name;
  166. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  167. if( $attachment_type_arr['value'] == 1 )
  168. {
  169. save_image_to_qiniu($fullname,$send_path.$last_img_name);
  170. }else if( $attachment_type_arr['value'] == 2 ){
  171. save_image_to_alioss($fullname,$send_path.$last_img_name);
  172. }
  173. $result = array('full_path' => date('Y-m-d')."/haibao_goods/".$last_img_name,'need_path' => date('Y-m-d')."/haibao_goods/".$last_img_name);
  174. return $result;
  175. }
  176. public function get_weindex_share_image($community_id,$wepro_qrcode,$avatar)
  177. {
  178. $community_info = D('Home/Front')->get_community_byid($community_id);
  179. $goods_ids_arr = M()->query('SELECT goods_id FROM ' . C('DB_PREFIX') . "lionfish_community_head_goods
  180. WHERE head_id=".$community_id." order by id desc ");
  181. $ids_arr = array();
  182. foreach($goods_ids_arr as $val){
  183. $ids_arr[] = $val['goods_id'];
  184. }
  185. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  186. WHERE is_all_sale=1 ");
  187. if( !empty($goods_ids_nolimit_arr) )
  188. {
  189. foreach($goods_ids_nolimit_arr as $val){
  190. $ids_arr[] = $val['id'];
  191. }
  192. }
  193. $ids_str = implode(',',$ids_arr);
  194. $where = " g.grounding =1 ";
  195. if( !empty($ids_str) )
  196. {
  197. $where .= " and g.id in ({$ids_str})";
  198. } else{
  199. $where .= " and 0 ";
  200. }
  201. $community_goods_list = $this->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction ', $where,0,8);
  202. $send_path = "Uploads/image/".date('Y-m-d')."/";
  203. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  204. RecursiveMkdir($image_dir);
  205. $bg_img = ROOT_PATH."/static/images/index_share_bg.jpg";
  206. $need_delete_image_arr = array();
  207. //index_share_qrcode_bg
  208. $index_share_qrcode_bg = D('Home/Front')->get_config_by_name('index_share_qrcode_bg');
  209. if( !empty($index_share_qrcode_bg) )
  210. {
  211. $bg_img = ROOT_PATH.'Uploads/image/' . $index_share_qrcode_bg;
  212. }
  213. $dst = imagecreatefromjpeg ($bg_img);
  214. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  215. $ttf_path = ROOT_PATH."/static/fonts/simhei.ttf";
  216. $msyh_path = ROOT_PATH."/static/fonts/msyh.ttf";
  217. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  218. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  219. //打上文字
  220. $black = imagecolorallocate($dst, 20,20,20);//黑色
  221. $a1a1a1 = imagecolorallocate($dst, 26,26,26);//黑色
  222. $red = imagecolorallocate($dst, 237, 48, 43); //红色 201 55 49
  223. $huise = imagecolorallocate($dst, 159, 159, 159); //灰色 159 159 159
  224. $fense = imagecolorallocate($dst, 248, 136, 161); //粉色 248 136 161
  225. $gray1 = imagecolorallocate($dst, 51, 51, 51); //#333 51, 51, 51
  226. $gray2 = imagecolorallocate($dst, 102, 102, 6); //#666 102, 102, 6
  227. $gray3 = imagecolorallocate($dst, 153, 153, 153); //#999 153, 153, 153
  228. $gray4 = imagecolorallocate($dst, 116, 116, 116); //#999 116, 116, 116
  229. $red_2 = imagecolorallocate($dst, 223, 21, 21); //#999 223, 21, 21
  230. //开始在图上画物体
  231. imagefttext($dst, 29, 0, 254, 228, $chengse, $pingfang_med_path, date('m月d日').'爆款');
  232. $avatar = str_replace('Uploads/image/','',$avatar);
  233. $avatar_img = resize($avatar, 30,30);
  234. list($avatar_img_img_w, $avatar_img_img_h, $avatar_img_img_type) = getimagesize(ROOT_PATH.$avatar_img);
  235. $avatar_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$avatar_img));
  236. if (imageistruecolor($avatar_img_src))
  237. imagetruecolortopalette($avatar_img_src, false, 65535);
  238. imagecopy($dst, $avatar_img_src, 162, 1105, 0, 0, $avatar_img_img_w, $avatar_img_img_h);
  239. $haibao_group_name = D('Home/Front')->get_config_by_name('haibao_group_name');
  240. if( empty($haibao_group_name) )
  241. {
  242. $haibao_group_name = '小区团长:';
  243. }
  244. imagefttext($dst, 20, 0, 32, 1130, $chengse, $pingfang_med_path, $haibao_group_name);
  245. $count = mb_strlen($community_info['disUserName'],'utf-8');
  246. $xin_str = '';
  247. for($i=1;$i<$count;$i++)
  248. {
  249. $xin_str .="*";
  250. }
  251. if($count>2)
  252. {
  253. $xin_str = '*'.mb_substr($community_info['disUserName'],-1,1,'utf-8');
  254. }
  255. imagefttext($dst, 20, 0, 198, 1130, $chengse, $pingfang_med_path, mb_substr($community_info['disUserName'],0,1,'utf-8').$xin_str );
  256. $modify_index_share_time = D('Home/Front')->get_config_by_name('modify_index_share_time');
  257. if(empty($modify_index_share_time))
  258. {
  259. $modify_index_share_time = date('H:00:00');
  260. }
  261. imagefttext($dst, 20, 0, 32, 1170, $chengse, $pingfang_med_path, '抢购时间:'.date('Y-m-d').' '.$modify_index_share_time);
  262. $fullAddress = $community_info['fullAddress'];
  263. $need_fullAddress = mb_substr($fullAddress,0,12,'utf-8')."\r\n";
  264. $need_fullAddress2 = mb_substr($fullAddress,12,11,'utf-8');
  265. //.'...'mb_strlen(
  266. if( mb_strlen($fullAddress,'utf-8') > 23)
  267. {
  268. $need_fullAddress2 .= '...';
  269. }
  270. imagefttext($dst, 20, 0, 32, 1203, $chengse, $pingfang_med_path, '提货地址:'.$need_fullAddress);
  271. imagefttext($dst, 20, 0, 160, 1233, $chengse, $pingfang_med_path, $need_fullAddress2);
  272. $i = 1;
  273. foreach($community_goods_list as $goods)
  274. {
  275. $skuImage = '';
  276. $good_image = $this->get_goods_images($goods['id']);
  277. if( empty($good_image) )
  278. {
  279. continue;
  280. }
  281. $skuImage = $good_image['image'];
  282. $thumb_goods_img = resize($skuImage,138,138);
  283. $need_delete_image_arr[] = ROOT_PATH.$thumb_goods_img;
  284. list($thumb_goods_img_w, $thumb_goods_img_h, $thumb_goods_img_type) = getimagesize(ROOT_PATH.$thumb_goods_img);
  285. $thumb_goods_img_src = $this->radius_img(ROOT_PATH.$thumb_goods_img, 138/2,3);
  286. if($thumb_goods_img_type == 'jpeg' || $thumb_goods_img_type == 'jpg')
  287. {
  288. $thumb_goods_img .= '.jpg';
  289. imagejpeg($thumb_goods_img_src, ROOT_PATH.$thumb_goods_img);
  290. }else{
  291. $thumb_goods_img .= '.png';
  292. imagepng($thumb_goods_img_src, ROOT_PATH.$thumb_goods_img);
  293. }
  294. imagedestroy($thumb_goods_img_src);
  295. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  296. if (imageistruecolor($goods_src))
  297. imagetruecolortopalette($goods_src, false, 65535);
  298. list($goods_src_w, $goods_src_h) = getimagesize(ROOT_PATH.$thumb_goods_img);
  299. $del_x = ($i % 2) == 0 ? 326 : 0;
  300. $del_y = ( ceil($i/2)-1) * 196;
  301. imagecopymerge($dst, $goods_src, 58+$del_x, 278+$del_y, 0, 0, $goods_src_w, $goods_src_h, 100);
  302. $price_arr = $this->get_goods_price($goods['id']);
  303. $price = $price_arr['price'];
  304. imagedestroy($goods_src);
  305. $goods_title = $goods['goodsname'];
  306. $need_goods_title = mb_substr($goods_title,0,6,'utf-8')."\r\n";
  307. $need_goods_title .= mb_substr($goods_title,6,5,'utf-8');
  308. //.'...'mb_strlen(
  309. if( mb_strlen($goods_title,'utf-8') > 11)
  310. {
  311. $need_goods_title .= '...';
  312. }
  313. imagefttext($dst, 18, 0, 208+$del_x, 315+$del_y, $gray1, $pingfang_med_path, $need_goods_title );
  314. imagefttext($dst, 14, 0, 208+$del_x, 375+$del_y, $gray4, $pingfang_med_path, '¥'.$goods['productprice'] );
  315. $size_12 = strlen($goods['productprice']);
  316. $pos = 225 + intval(13 * ($size_12 -1) -3 );
  317. imageline($dst, 225+$del_x, 368+$del_y, $pos+$del_x, 368+$del_y, $gray3); //画线
  318. imagefttext($dst, 18, 0, 208+$del_x, 410+$del_y, $red_2, $pingfang_path, '¥'.$price );
  319. //break;
  320. $i++;
  321. }
  322. $thumb_goods_img = $wepro_qrcode;
  323. $need_delete_image_arr[] = ROOT_PATH.$thumb_goods_img;
  324. $wepro_qrcode = str_replace('Uploads/image/','',$wepro_qrcode);
  325. $thumb_goods_img = resize($wepro_qrcode,180,180);
  326. list($thumb_goods_img_w, $thumb_goods_img_h, $thumb_goods_img_type) = getimagesize(ROOT_PATH.$thumb_goods_img);
  327. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  328. $thumb_goods_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  329. if (imageistruecolor($thumb_goods_img_src))
  330. imagetruecolortopalette($thumb_goods_img_src, false, 65535);
  331. imagecopy($dst, $goods_src, 516, 1098, 0, 0, $thumb_goods_img_w, $thumb_goods_img_h);
  332. //结束图上画物体
  333. $last_img = $image_dir;
  334. $last_img_name = "last_index_".md5( time().$community_id.mt_rand(1,999)).'';
  335. switch ($dst_type) {
  336. case 1://GIF
  337. $last_img_name .= '.gif';
  338. header('Content-Type: image/gif');
  339. imagegif($dst, $last_img.$last_img_name);
  340. break;
  341. case 2://JPG
  342. $last_img_name .= '.jpg';
  343. //header('Content-Type: image/jpeg');
  344. imagejpeg($dst, $last_img.$last_img_name);
  345. break;
  346. case 3://PNG
  347. $last_img_name .= '.png';
  348. header('Content-Type: image/png');
  349. imagepng($dst, $last_img.$last_img_name);
  350. break;
  351. default:
  352. break;
  353. }
  354. imagedestroy($dst);
  355. //imagedestroy($goods_src);
  356. $result = array('full_path' => $send_path.$last_img_name,'need_path' => $send_path.$last_img_name);
  357. foreach( $need_delete_image_arr as $del_img )
  358. {
  359. @unlink($del_img);
  360. }
  361. return $result;
  362. }
  363. public function check_qiniu_image($goods_img_info_image)
  364. {
  365. global $_W;
  366. global $_GPC;
  367. if (!empty($_W['setting']['remote']['type']))
  368. {
  369. $header = array(
  370. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  371. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  372. 'Accept-Encoding: gzip, deflate',);
  373. $goods_img = tomedia( $goods_img_info_image);
  374. $curl = curl_init();
  375. curl_setopt($curl, CURLOPT_URL, $goods_img);
  376. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  377. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  378. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  379. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  380. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  381. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  382. $data = curl_exec($curl);
  383. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  384. curl_close($curl);
  385. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  386. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  387. }
  388. $img_content=$imgBase64Code;//图片内容
  389. //echo $img_content;exit;
  390. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  391. {
  392. $type = $result[2];//得到图片类型png?jpg?gif?
  393. $send_path = "images/".date('Y-m-d')."/";
  394. $image_dir = ATTACHMENT_ROOT.$send_path; //上传文件路径
  395. load()->func('file');
  396. mkdirs($image_dir);
  397. $new_file = md5($goods_img).".{$type}";
  398. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  399. $goods_img_info_image = $send_path.$new_file;
  400. }
  401. }
  402. return $goods_img_info_image;
  403. }
  404. public function get_goods_tags($label_id)
  405. {
  406. $tag_info = M('lionfish_comshop_goods_tags')->field('id,tagname,type,tagcontent')->where( array('id' => $label_id) )->find();
  407. return $tag_info;
  408. }
  409. public function get_min_time(){
  410. global $_W;
  411. global $_GPC;
  412. $now_time = time();
  413. //$where = ' begin_time <='. $now_time.' and end_time > '.$now_time;
  414. //$sql = "select min(end_time) as rushtime from ".C('DB_PREFIX')."lionfish_comshop_good_common where ".$where." ";
  415. $where = ' gc.begin_time <='. $now_time.' and gc.end_time > '.$now_time.' and g.id=gc.goods_id and g.grounding=1 and g.is_index_show=1 and gc.is_new_buy=0 and gc.is_spike_buy = 0 ';
  416. $sql = "select min(gc.end_time) as rushtime from " .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc where {$where}";
  417. $rushtime_arr = M()->query($sql);
  418. $rushtime = $rushtime_arr[0];
  419. return $rushtime['rushtime'];
  420. }
  421. /**
  422. * 获取即将抢购商品总数
  423. * @return [string] [总数]
  424. */
  425. public function get_comming_goods_count(){
  426. $now_time = time();
  427. $where .= " begin_time > {$now_time} ";
  428. $count = M('lionfish_comshop_good_common')->where( " begin_time > {$now_time} " )->count();
  429. return $count;
  430. }
  431. //end index_share_qrcode
  432. public function get_weshare_image($goods_id)
  433. {
  434. $goods_info = M('lionfish_comshop_goods')->field('goodsname,price,productprice,sales,seller_count,total')->where( array('id' => $goods_id) )->find();
  435. $goods_img_info = $this->get_goods_images($goods_id);
  436. $goods_img = ROOT_PATH.'Uploads/image/' . $goods_img_info['image'];
  437. $goods_price = $this->get_goods_price($goods_id);
  438. $goods_price['market_price'] = $goods_info['productprice'];
  439. $goods_title = $goods_info['goodsname'];
  440. $seller_count = $goods_info['seller_count'] + $goods_info['sales'];
  441. $quantity = $goods_info['total'];
  442. $need_img = $this->_get_compare_zan_img($goods_img_info['image'], $goods_title, $goods_price,$seller_count,$quantity);
  443. //贴上二维码图
  444. $up_data = array();
  445. $up_data['wepro_qrcode_image'] = $need_img['need_path'];
  446. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save( $up_data );
  447. return true;
  448. }
  449. function radius_img($imgpath = './t.png', $radius = 15, $color=1) {
  450. $ext = pathinfo($imgpath);
  451. $src_img = null;
  452. switch ($ext['extension']) {
  453. case 'jpg':
  454. $src_img = imagecreatefromjpeg($imgpath);
  455. break;
  456. case 'jpeg':
  457. $src_img = imagecreatefromjpeg($imgpath);
  458. break;
  459. case 'png':
  460. $src_img = imagecreatefrompng($imgpath);
  461. break;
  462. }
  463. $wh = getimagesize($imgpath);
  464. $w = $wh[0];
  465. $h = $wh[1];
  466. // $radius = $radius == 0 ? (min($w, $h) / 2) : $radius;
  467. $img = imagecreatetruecolor($w, $h);
  468. //这一句一定要有
  469. imagesavealpha($img, true);
  470. //拾取一个完全透明的颜色,最后一个参数127为全透明
  471. //拾取一个完全透明的颜色,最后一个参数127为全透明 int $red , int $green , int $blu
  472. if($color == 1)
  473. {
  474. $bg = imagecolorallocatealpha($img, 244, 91, 86, 127);
  475. }else if($color == 2){
  476. //
  477. $avatar_rgb = D('Home/Front')->get_config_by_name('avatar_rgb' );
  478. if( !empty($avatar_rgb) )
  479. {
  480. $rgb_arr = $this->hex2rgb($avatar_rgb);
  481. $bg = imagecolorallocatealpha($img, $rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b'], 127);
  482. }else{
  483. $bg = imagecolorallocatealpha($img, 255, 245, 98, 127);
  484. }
  485. }else if($color == 3){
  486. $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
  487. }else if($color == 4){
  488. $bg = imagecolorallocatealpha($img, 252, 243, 10, 127);
  489. }else if($color == 5){
  490. $avatar_rgb = D('Home/Front')->get_config_by_name('commiss_avatar_rgb' );
  491. if( !empty($avatar_rgb) )
  492. {
  493. $rgb_arr = $this->hex2rgb($avatar_rgb);
  494. $bg = imagecolorallocatealpha($img, $rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b'], 127);
  495. }else{
  496. $bg = imagecolorallocatealpha($img, 255, 245, 98, 127);
  497. }
  498. }
  499. imagefill($img, 0, 0, $bg);
  500. $r = $radius; //圆 角半径
  501. for ($x = 0; $x < $w; $x++) {
  502. for ($y = 0; $y < $h; $y++) {
  503. $rgbColor = imagecolorat($src_img, $x, $y);
  504. if (($x >= $radius && $x <= ($w - $radius)) || ($y >= $radius && $y <= ($h - $radius))) {
  505. //不在四角的范围内,直接画
  506. imagesetpixel($img, $x, $y, $rgbColor);
  507. } else {
  508. //在四角的范围内选择画
  509. //上左
  510. $y_x = $r; //圆心X坐标
  511. $y_y = $r; //圆心Y坐标
  512. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  513. imagesetpixel($img, $x, $y, $rgbColor);
  514. }
  515. //上右
  516. $y_x = $w - $r; //圆心X坐标
  517. $y_y = $r; //圆心Y坐标
  518. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  519. imagesetpixel($img, $x, $y, $rgbColor);
  520. }
  521. //下左
  522. $y_x = $r; //圆心X坐标
  523. $y_y = $h - $r; //圆心Y坐标
  524. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  525. imagesetpixel($img, $x, $y, $rgbColor);
  526. }
  527. //下右
  528. $y_x = $w - $r; //圆心X坐标
  529. $y_y = $h - $r; //圆心Y坐标
  530. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  531. imagesetpixel($img, $x, $y, $rgbColor);
  532. }
  533. }
  534. }
  535. }
  536. return $img;
  537. }
  538. public function get_user_avatar($url, $member_id,$color=1)
  539. {
  540. //wepro_qrcode
  541. $header = array(
  542. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  543. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  544. 'Accept-Encoding: gzip, deflate',);
  545. $curl = curl_init();
  546. curl_setopt($curl, CURLOPT_URL, $url);
  547. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  548. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  549. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // false for https
  550. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  551. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  552. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  553. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
  554. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
  555. $data = curl_exec($curl);
  556. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  557. curl_close($curl);
  558. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  559. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  560. }
  561. $img_content=$imgBase64Code;//图片内容
  562. //echo $img_content;exit;
  563. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  564. {
  565. $type = $result[2];//得到图片类型png?jpg?gif?
  566. $image_dir = ROOT_PATH.'Uploads/image/';
  567. $send_path = 'goods/'.date('Y-m-d').'/';
  568. $image_dir .= $send_path;
  569. RecursiveMkdir($image_dir);
  570. $new_file = md5($url).".{$type}";
  571. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  572. if ($res)
  573. {
  574. list($src_w, $src_h) = getimagesize($image_dir.$new_file);
  575. if($color != 1)
  576. {
  577. $thumb_image_name = resize($send_path.$new_file, 32,32);
  578. $new_file = $thumb_image_name;
  579. //$new_file = str_replace($send_path,'',$new_file);
  580. $imgg = $this->radius_img(ROOT_PATH.$new_file, 32/2,$color);
  581. }else{
  582. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,$color);
  583. $new_file = 'Uploads/image/'.$send_path.$new_file;
  584. }
  585. if($type == 'jpeg' || $type == 'jpg')
  586. {
  587. imagejpeg($imgg, ROOT_PATH.$new_file);
  588. }else{
  589. imagepng($imgg, ROOT_PATH.$new_file);
  590. }
  591. //imagepng($imgg);
  592. //imagegif($imgg)
  593. imagedestroy($imgg);
  594. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('wepro_qrcode' => $new_file) );
  595. return $new_file;
  596. }else{
  597. return '';
  598. }
  599. }
  600. }
  601. public function get_commission_user_avatar($url, $member_id,$color=1)
  602. {
  603. global $_W;
  604. global $_GPC;
  605. //wepro_qrcode
  606. $header = array(
  607. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  608. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  609. 'Accept-Encoding: gzip, deflate',);
  610. $curl = curl_init();
  611. curl_setopt($curl, CURLOPT_URL, $url);
  612. if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
  613. curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  614. }
  615. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  616. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  617. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // false for https
  618. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  619. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  620. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  621. $data = curl_exec($curl);
  622. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  623. curl_close($curl);
  624. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  625. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  626. }
  627. $img_content=$imgBase64Code;//图片内容
  628. //echo $img_content;exit;
  629. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  630. {
  631. $type = $result[2];//得到图片类型png?jpg?gif?
  632. $image_dir = ROOT_PATH.'Uploads/image/';
  633. $send_path = 'goods/'.date('Y-m-d').'/';
  634. $image_dir .= $send_path;
  635. RecursiveMkdir($image_dir);
  636. $new_file = md5($url).".{$type}";
  637. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  638. if ($res)
  639. {
  640. list($src_w, $src_h) = getimagesize($image_dir.$new_file);
  641. if($color == 5)
  642. {
  643. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,5);
  644. }
  645. else if($color != 1)
  646. {
  647. $thumb_image_name = resize($send_path.$new_file, 100,100);
  648. $new_file = $thumb_image_name;
  649. $new_file = str_replace($send_path,'',$new_file);
  650. $imgg = $this->radius_img($image_dir.$new_file, 100/2,$color);
  651. }else{
  652. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,$color);
  653. }
  654. if($type == 'jpeg' || $type == 'jpg')
  655. {
  656. imagejpeg($imgg, $image_dir.$new_file);
  657. }else{
  658. imagepng($imgg, $image_dir.$new_file);
  659. }
  660. imagedestroy($imgg);
  661. return $send_path.$new_file;
  662. }else{
  663. return '';
  664. }
  665. }
  666. }
  667. public function _get_compare_qrcode_bgimg($bg_img, $qrcode_img,$avatar_image,$username, $s_x = '520',$s_y = '900')
  668. {
  669. //$image_dir = ROOT_PATH.'Uploads/image/';
  670. $send_path = "Uploads/image/".date('Y-m-d')."/";
  671. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  672. RecursiveMkdir($image_dir);
  673. $thumb_image_name = resize($qrcode_img, 230,230);
  674. $thumb_qrcode_img = ROOT_PATH.$thumb_image_name;
  675. $thumb_avatar_img = ROOT_PATH.$avatar_image;
  676. $bg_img = ROOT_PATH.$bg_img;
  677. $dst = imagecreatefromjpeg ($bg_img);
  678. $src = imagecreatefromstring(file_get_contents($thumb_qrcode_img));
  679. $src_avatar = imagecreatefromstring(file_get_contents($thumb_avatar_img));
  680. if (imageistruecolor($src))
  681. imagetruecolortopalette($src, false, 65535);
  682. list($src_w, $src_h) = getimagesize($thumb_qrcode_img);
  683. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  684. imagecopymerge($dst, $src, 442, 1020, 0, 0, $src_w, $src_h, 100);
  685. list($src_w, $src_h) = getimagesize($thumb_avatar_img);
  686. //list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  687. imagecopymerge($dst, $src_avatar, 65, 45, 0, 0, $src_w, $src_h, 100);
  688. $last_img = $image_dir;
  689. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  690. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  691. $gray1 = imagecolorallocate($dst, 23, 23, 23); //#333 51, 51, 51
  692. $white = imagecolorallocate($dst, 255, 255, 255); //#333 51, 51, 51
  693. $yellow = imagecolorallocate($dst, 255, 255, 0); //#333 51, 51, 51
  694. imagefttext($dst, 20, 0, 470, 1297, $gray1, $pingfang_med_path, '长按识别小程序');
  695. // $username = "试试我可以有多长,好长好长好长好长好长好长";
  696. $username = mb_substr($username,0,12,'utf-8');
  697. imagefttext($dst, 30, 0, 212, 94, $white, $pingfang_med_path, '@'.$username);
  698. $desc_txt = "分享了一个好东西";
  699. imagefttext($dst, 26, 0, 212, 148, $yellow, $pingfang_med_path, $desc_txt);
  700. $last_img_name = "last_qrcode".md5( time().$bg_img.$qrcode_img).'';
  701. switch ($dst_type) {
  702. case 1://GIF
  703. $last_img_name .= '.gif';
  704. header('Content-Type: image/gif');
  705. imagegif($dst, $last_img.$last_img_name);
  706. break;
  707. case 2://JPG
  708. $last_img_name .= '.jpg';
  709. //header('Content-Type: image/jpeg');
  710. imagejpeg($dst, $last_img.$last_img_name);
  711. break;
  712. case 3://PNG
  713. $last_img_name .= '.png';
  714. header('Content-Type: image/png');
  715. imagepng($dst, $last_img.$last_img_name);
  716. break;
  717. default:
  718. break;
  719. }
  720. imagedestroy($dst);
  721. imagedestroy($src);
  722. //imagedestroy($goods_src);
  723. //imagedestroy($avatar_src);
  724. //return_file_path
  725. $result = array('full_path' => $send_path.$last_img_name,'need_path' => $send_path.$last_img_name);
  726. return $result;
  727. }
  728. public function _get_commmon_wxqrcode($path='',$scene)
  729. {
  730. /**
  731. $jssdk = new \Lib\Weixin\Jssdk( C('weprogram_appid'), C('weprogram_appscret') );
  732. $weqrcode = $jssdk->getAllWeQrcode('pages/order/hexiao_bind',SELLERUID.'_0' );
  733. //保存图片
  734. $image_dir = ROOT_PATH.'Uploads/image/goods';
  735. $image_dir .= '/'.date('Y-m-d').'/';
  736. $file_path = C('SITE_URL').'Uploads/image/goods/'.date('Y-m-d').'/';
  737. $kufile_path = $dir.'/'.date('Y-m-d').'/';
  738. RecursiveMkdir($image_dir);
  739. $file_name = md5('qrcode_'.$pick_order_info['pick_sn'].time()).'.png';
  740. file_put_contents($image_dir.$file_name, $weqrcode);
  741. **/
  742. $weixin_config = array();
  743. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  744. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  745. $qrcode_rgb = D('Home/Front')->get_config_by_name('qrcode_rgb');
  746. if( !empty($qrcode_rgb) )
  747. {
  748. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  749. }
  750. //qrcode
  751. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  752. //$weqrcode = $jssdk->getAllWeQrcode($path,$scene);
  753. $weqrcode = $jssdk->getAllWeQrcode($path,$scene ,false,$qrcode_arr);
  754. $res_ck = json_decode($weqrcode, true);
  755. if( !empty($res_ck) && isset($res_ck['errcode']) )
  756. {
  757. return '';
  758. }else {
  759. //保存图片
  760. $image_dir = ROOT_PATH.'Uploads/image/';
  761. $image_dir .= 'goods'.date('Y-m-d').'/';
  762. RecursiveMkdir($image_dir);
  763. $file_name = md5('qrcode_'.$weqrcode.time()).'.png';
  764. file_put_contents($image_dir.$file_name, $weqrcode);
  765. //.......
  766. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  767. if( $attachment_type_arr['value'] == 1 )
  768. {
  769. save_image_to_qiniu($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  770. }else if( $attachment_type_arr['value'] == 2 ){
  771. save_image_to_alioss($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  772. }else if( $attachment_type_arr['value'] == 3 ){
  773. $res = save_image_to_txyun($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  774. }
  775. return 'goods'.date('Y-m-d').'/'.$file_name;
  776. }
  777. }
  778. function hex2rgb( $colour ) {
  779. if ( $colour[0] == '#' ) {
  780. $colour = substr( $colour, 1 );
  781. }
  782. if ( strlen( $colour ) == 6 ) {
  783. list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
  784. } elseif ( strlen( $colour ) == 3 ) {
  785. list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
  786. } else {
  787. return false;
  788. }
  789. $r = hexdec( $r );
  790. $g = hexdec( $g );
  791. $b = hexdec( $b );
  792. return array( 'r' => $r, 'g' => $g, 'b' => $b );
  793. }
  794. public function _get_index_wxqrcode($member_id,$community_id)
  795. {
  796. $weixin_config = array();
  797. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  798. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  799. $qrcode_rgb = D('Home/Front')->get_config_by_name('qrcode_rgb');
  800. $qrcode_arr = array();
  801. if( !empty($qrcode_rgb) )
  802. {
  803. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  804. }
  805. //qrcode
  806. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  807. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/pages/index/index',$community_id .'_'. $member_id,true,$qrcode_arr);
  808. //line_color
  809. //保存图片
  810. $send_path = "Uploads/image/".date('Y-m-d')."/";
  811. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  812. RecursiveMkdir($image_dir);
  813. $file_name = md5('qrcode_'.$goods_id.'_'.$member_id.time()).'.png';
  814. //qrcode
  815. file_put_contents($image_dir.$file_name, $weqrcode);
  816. return $send_path.$file_name;
  817. }
  818. public function _get_goods_user_wxqrcode($goods_id,$member_id,$community_id)
  819. {
  820. $weixin_config = array();
  821. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  822. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  823. //qrcode
  824. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  825. $qrcode_rgb = D('Home/Front')->get_config_by_name('qrcode_rgb');
  826. if( !empty($qrcode_rgb) )
  827. {
  828. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  829. }
  830. //lionfish_comshop/pages/goods/goodsDetail
  831. if($goods_id == 0)
  832. {
  833. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/pages/index/index',$goods_id.'_'.$member_id.'_'.$community_id ,false,$qrcode_arr);
  834. }else{
  835. $gd_info = M('lionfish_comshop_goods')->field('type')->where( array('id'=>$goods_id) )->find();
  836. if( $gd_info['type'] == 'pin' )
  837. {
  838. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/moduleA/pin/goodsDetail',$goods_id.'_'.$member_id.'_'.$community_id ,false,$qrcode_arr);
  839. }else{
  840. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/pages/goods/goodsDetail',$goods_id.'_'.$member_id.'_'.$community_id ,false,$qrcode_arr);
  841. }
  842. }
  843. //line_color
  844. //var_dump($weqrcode);die();
  845. //保存图片
  846. $send_path = "Uploads/image/goods/".date('Y-m-d')."/";
  847. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  848. $send_path_re = "goods/".date('Y-m-d')."/";
  849. RecursiveMkdir($image_dir);
  850. $file_name = md5('qrcode_'.$goods_id.'_'.$member_id.time()).'.jpg';
  851. //qrcode
  852. file_put_contents($image_dir.$file_name, $weqrcode);
  853. return $send_path_re.$file_name;
  854. }
  855. public function _get_compare_zan_img($goods_img,$goods_title,$goods_price, $seller_count,$quantity)
  856. {
  857. $send_path = "Uploads/image/goods/".date('Y-m-d')."/";
  858. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  859. $send_path_re = "goods/".date('Y-m-d')."/";
  860. RecursiveMkdir($image_dir);
  861. $bg_img = ROOT_PATH."/static/images/bg2.jpg";
  862. $thumb_goods_name = "thumb_img".md5($goods_img).'.png';
  863. $thumb_goods_img = resize($goods_img,700,700);
  864. $image_dir = ROOT_PATH.$send_path;
  865. $return_file_path = $send_path;
  866. //$image_dir.$thumb_avatar_name
  867. //商品图片 25 215
  868. //文字:65 955
  869. //长按二维码领取: 517 640
  870. //商品文字: 24 710
  871. //快和我一起领取吧: 24 817
  872. //市场价,单价 24 895
  873. //var_dump($thumb_goods_img);die();
  874. //$dst = imagecreatefromstring(file_get_contents($bg_img));
  875. $dst = imagecreatefromjpeg ($bg_img);
  876. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  877. if (imageistruecolor($goods_src))
  878. imagetruecolortopalette($goods_src, false, 65535);
  879. list($goods_src_w, $goods_src_h) = getimagesize(ROOT_PATH.$thumb_goods_img);
  880. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  881. imagecopymerge($dst, $goods_src, 25, 215, 0, 0, $goods_src_w, $goods_src_h, 100);
  882. //imagecopymerge($dst, $avatar_src, 24, 615, 0, 0, $avatar_w, $avatar_h, 100);
  883. //IA_ROOT."/addons/lionfish_comshop/static/fonts/simhei.ttf"
  884. //$ttf_path = ROOT_PATH."Common/js/simhei.ttf";
  885. $ttf_path = ROOT_PATH."/static/fonts/simhei.ttf";
  886. $msyh_path = ROOT_PATH."/static/fonts/msyh.ttf";
  887. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  888. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  889. //打上文字
  890. $black = imagecolorallocate($dst, 20,20,20);//黑色
  891. $red = imagecolorallocate($dst, 237, 48, 43); //红色 201 55 49
  892. $huise = imagecolorallocate($dst, 159, 159, 159); //灰色 159 159 159
  893. $fense = imagecolorallocate($dst, 248, 136, 161); //粉色 248 136 161
  894. $gray1 = imagecolorallocate($dst, 51, 51, 51); //#333 51, 51, 51
  895. $gray2 = imagecolorallocate($dst, 102, 102, 6); //#666 102, 102, 6
  896. $gray3 = imagecolorallocate($dst, 153, 153, 153); //#999 153, 153, 153
  897. $chengse = imagecolorallocate($dst, 252, 74, 74); //#999
  898. //ffb7d7 248 136 161
  899. // $goods_title = "我免费领取了【大白兔奶糖果零食铁盒装114g】的所得税的色舞认太热太热太热";
  900. $goods_title = $goods_title;
  901. $need_goods_title = mb_substr($goods_title,0,18,'utf-8')."\r\n";
  902. $need_goods_title .= mb_substr($goods_title,18,9,'utf-8');
  903. //.'...'mb_strlen(
  904. if( mb_strlen($goods_title,'utf-8') > 28)
  905. {
  906. $need_goods_title .= '...';
  907. }
  908. //imagefttext($dst, 25, 0, 120, 660, $black, $ttf_path, $username);
  909. //imagefttext($dst, 15, 0, 518, 920, $huise, $ttf_path, '长按二维码领取'); 65 955
  910. imagefttext($dst, 26, 0, 64, 987, $gray1, $pingfang_med_path, $need_goods_title);
  911. // imagefttext($dst, 15, 0, 25, 1040, $fense, $ttf_path, "限时爆款价");
  912. imagefttext($dst, 22, 0, 64, 1165, $chengse, $pingfang_path, "团购价:");
  913. imagefttext($dst, 32, 0, 178, 1168, $chengse, $pingfang_path, '¥'.$goods_price['price']);
  914. $size_1 = sprintf('%.2f',$goods_price['market_price']);
  915. $size_12 = strlen($size_1);
  916. imagefttext($dst, 18, 0, 64, 1115, $gray3, $pingfang_med_path, "原价:¥".$size_1 );
  917. $pos = 145 + intval(15 * ($size_12-1)+5);
  918. imageline($dst, 122, 1105, $pos, 1105, $gray3); //画线
  919. //imageline($dst, 122, 1105, $pos, 1105, $gray3); //画线
  920. imagefttext($dst, 16, 0, 64, 1270, $chengse, $pingfang_med_path, "已售{$seller_count}件");
  921. imagefttext($dst, 16, 0, 212, 1270, $chengse, $pingfang_med_path, "仅剩{$quantity}件");
  922. //$seller_count,$quantity 已售10件
  923. $last_img = $image_dir;
  924. $last_img_name = "last_avatar".md5( time().$need_goods_title.$username).'';
  925. switch ($dst_type) {
  926. case 1://GIF
  927. $last_img_name .= '.gif';
  928. header('Content-Type: image/gif');
  929. imagegif($dst, $last_img.$last_img_name);
  930. break;
  931. case 2://JPG
  932. $last_img_name .= '.jpg';
  933. //header('Content-Type: image/jpeg');
  934. imagejpeg($dst, $last_img.$last_img_name);
  935. break;
  936. case 3://PNG
  937. $last_img_name .= '.png';
  938. header('Content-Type: image/png');
  939. imagepng($dst, $last_img.$last_img_name);
  940. break;
  941. default:
  942. break;
  943. }
  944. imagedestroy($dst);
  945. imagedestroy($goods_src);
  946. //imagedestroy($avatar_src); imageistruecolor
  947. //return_file_path
  948. $result = array('full_path' => $send_path.$last_img_name,'need_path' => $send_path_re.$last_img_name);
  949. return $result;
  950. }
  951. /**
  952. 关注取消商品收藏
  953. 删除返回1
  954. **/
  955. public function user_fav_goods_toggle($goods_id, $member_id)
  956. {
  957. $res = $this->check_goods_fav($goods_id, $member_id);
  958. if($res)
  959. {
  960. //删除
  961. M('lionfish_comshop_user_favgoods')->where( array('goods_id' => $goods_id,'member_id' => $member_id) )->delete();
  962. return 1;
  963. } else {
  964. //添加
  965. $data = array();
  966. $data['member_id'] = $member_id;
  967. $data['goods_id'] = $goods_id;
  968. $data['add_time'] = time();
  969. M('lionfish_comshop_user_favgoods')->add($data);
  970. return 2;
  971. }
  972. }
  973. public function check_goods_fav($goods_id, $member_id)
  974. {
  975. $user_favgoods = M('lionfish_comshop_user_favgoods')->where( array('member_id' => $member_id, 'goods_id' => $goods_id) )->find();
  976. if(!empty($user_favgoods))
  977. {
  978. return true;
  979. } else {
  980. return false;
  981. }
  982. }
  983. /**
  984. 获取商品的分佣金额
  985. **/
  986. public function get_goods_commission_info($goods_id,$member_id, $is_parse = false)
  987. {
  988. $result = array();
  989. //1 比例,2固定金额
  990. $result['commiss_one'] = array('money' => 0,'fen' => 0, 'type' => 1);
  991. $result['commiss_two'] = array('money' => 0,'fen' => 0, 'type' => 1);
  992. $result['commiss_three'] = array('money' => 0,'fen' => 0, 'type' => 1);
  993. $goods_commiss = M('lionfish_comshop_good_commiss')->where( array('goods_id' => $goods_id ) )->find();
  994. $gd_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $goods_id ) )->find();
  995. if($goods_commiss['nocommission'] == 1 || $gd_info['type'] == 'integral' )
  996. {
  997. return $result;
  998. }else{
  999. //hascommission
  1000. if($goods_commiss['hascommission'] == 1 || $is_parse)
  1001. {
  1002. //自定义商品分佣
  1003. if( !empty($goods_commiss['commission1_rate']) && $goods_commiss['commission1_rate'] >0 )
  1004. {
  1005. $result['commiss_one'] = array('money' => 0,'fen' => $goods_commiss['commission1_rate'], 'type' => 1);
  1006. }else{
  1007. $result['commiss_one'] = array('money' => $goods_commiss['commission1_pay'],'fen' => 0, 'type' => 2);
  1008. }
  1009. if( !empty($goods_commiss['commission2_rate']) && $goods_commiss['commission2_rate'] >0 )
  1010. {
  1011. $result['commiss_two'] = array('money' => 0,'fen' => $goods_commiss['commission2_rate'], 'type' => 1);
  1012. }else{
  1013. $result['commiss_two'] = array('money' => $goods_commiss['commission2_pay'],'fen' => 0, 'type' => 2);
  1014. }
  1015. if( !empty($goods_commiss['commission3_rate']) && $goods_commiss['commission3_rate'] >0 )
  1016. {
  1017. $result['commiss_three'] = array('money' => 0,'fen' => $goods_commiss['commission3_rate'], 'type' => 1);
  1018. }else{
  1019. $result['commiss_three'] = array('money' => $goods_commiss['commission3_pay'],'fen' => 0, 'type' => 2);
  1020. }
  1021. $parent_info = D('Home/Commission')->get_member_parent_list($member_id);
  1022. $result['parent_info'] = $parent_info;
  1023. }else{
  1024. //是否开启分销内购 commiss_selfbuy
  1025. $commiss_level_info = D('Home/Commission')->get_commission_level();
  1026. $commiss_selfbuy = D('Home/Front')->get_config_by_name('commiss_selfbuy');
  1027. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1028. $parent_info = D('Home/Commission')->get_member_parent_list($member_id);
  1029. if($commiss_selfbuy == 1)
  1030. {
  1031. //开启分销内购
  1032. if( $member_info['comsiss_state'] == 1 && $member_info['comsiss_flag'] == 1 )
  1033. {
  1034. $parent_info['self_go'] = array('member_id' =>$member_id, 'level_id' => $member_info['commission_level_id']);
  1035. }
  1036. }
  1037. //开始分析分佣比例
  1038. if( isset($parent_info['self_go']) && !empty($parent_info['self_go']['member_id']) )
  1039. {
  1040. $result['commiss_one'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['self_go']['level_id'] ]['commission'], 'type' => 1);
  1041. $result['commiss_two'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['one']['level_id']]['commission2'], 'type' => 1);
  1042. $result['commiss_three'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['two']['level_id']]['commission3'], 'type' => 1);
  1043. }else{
  1044. $result['commiss_one'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['one']['level_id']]['commission'], 'type' => 1);
  1045. $result['commiss_two'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['two']['level_id']]['commission2'], 'type' => 1);
  1046. $result['commiss_three'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['three']['level_id']]['commission3'], 'type' => 1);
  1047. }
  1048. }
  1049. return $result;
  1050. }
  1051. }
  1052. /**
  1053. 获取商品列表
  1054. **/
  1055. public function get_goods_list($fields='*', $where='1=1',$order='index_sort desc ,seller_count desc,id asc',$offset=0,$perpage=10)
  1056. {
  1057. $list = M('lionfish_comshop_goods')->field($fields)->where($where)->order($order)->limit($offset,$perpage)->select();
  1058. return $list;
  1059. }
  1060. /**
  1061. 获取商品图片
  1062. **/
  1063. public function get_goods_images($goods_id, $limit =1)
  1064. {
  1065. if($limit == 1)
  1066. {
  1067. $image_info = M('lionfish_comshop_goods_images')->where( array('goods_id' => $goods_id) )->order('id asc')->find();
  1068. return $image_info;
  1069. }else{
  1070. $image_list = M('lionfish_comshop_goods_images')->where( array('goods_id' => $goods_id) )->order('id asc')->select();
  1071. return $image_list;
  1072. }
  1073. }
  1074. /**
  1075. 商品喜欢的数量
  1076. **/
  1077. public function fav_goods_count($goods_id)
  1078. {
  1079. $total = M('lionfish_comshop_user_favgoods')->where( array('goods_id' => $goods_id) )->count();
  1080. return $total;
  1081. }
  1082. /**
  1083. 会员喜欢商品状态
  1084. **/
  1085. public function fav_goods_state($goods_id, $member_id)
  1086. {
  1087. $fav_info = M('lionfish_comshop_user_favgoods')->where( array('goods_id' => $goods_id, 'member_id' => $member_id) )->find();
  1088. return $fav_info;
  1089. }
  1090. /**
  1091. 获取商品价格
  1092. **/
  1093. public function get_goods_price($goods_id,$member_id = 0)
  1094. {
  1095. $price_arr = array();
  1096. $goods_info = M('lionfish_comshop_goods')->field('price as danprice,type,card_price')->where( array('id' => $goods_id))->find();
  1097. if($goods_info['type'] =='pin')
  1098. {
  1099. $pin_goods_info = M('lionfish_comshop_good_pin')->field('pinprice,pin_count')->where( array('goods_id' => $goods_id ) )->find();
  1100. if(!empty($pin_goods_info))
  1101. {
  1102. $price_arr = array('price' =>$pin_goods_info['pinprice'],'danprice' =>$goods_info['danprice'], 'pin_price' =>$pin_goods_info['pinprice'],'pin_count' => $pin_goods_info['pin_count']);
  1103. $option_price_arr = M('lionfish_comshop_goods_option_item_value')->field('marketprice as dan_price')->where( array('goods_id' => $goods_id ) )->order('marketprice asc')->find();
  1104. if( !empty($option_price_arr) )
  1105. {
  1106. $price_arr['danprice'] = $option_price_arr['dan_price'];
  1107. }
  1108. $option_pinprice_arr = M('lionfish_comshop_goods_option_item_value')->field('pinprice as pin_price')->where( array('goods_id' => $goods_id) )->order('pinprice asc')->find();
  1109. if( !empty($option_pinprice_arr) )
  1110. {
  1111. $price_arr['price'] = $option_pinprice_arr['pin_price'];
  1112. $price_arr['pin_price'] = $option_pinprice_arr['pin_price'];
  1113. }
  1114. }
  1115. }else{
  1116. //获取最低价格
  1117. $option_price_arr = M('lionfish_comshop_goods_option_item_value')->field('id,marketprice as dan_price')
  1118. ->where( array('goods_id' => $goods_id) )->order('marketprice asc')->find();
  1119. $max_option_price_arr = M('lionfish_comshop_goods_option_item_value')
  1120. ->field('id,marketprice as dan_price')->where( array('goods_id' => $goods_id) )
  1121. ->order('marketprice desc')->find();
  1122. if( !empty($option_price_arr) && $option_price_arr['dan_price'] >= 0.01)
  1123. {
  1124. $price_arr = array('price' => $option_price_arr['dan_price'],'danprice' => $option_price_arr['dan_price']);
  1125. if( $max_option_price_arr['dan_price'] > $option_price_arr['dan_price'])
  1126. {
  1127. $price_arr['max_danprice'] = $max_option_price_arr['dan_price'];
  1128. }
  1129. }else{
  1130. $price_arr = array('price' => $goods_info['danprice'],'danprice' => $goods_info['danprice']);
  1131. }
  1132. $option_cardprice_arr = M('lionfish_comshop_goods_option_item_value')->field('id,card_price')->where( array('goods_id' => $goods_id ) )->order('card_price asc')->find();
  1133. if( !empty($option_cardprice_arr) && $option_cardprice_arr['card_price'] >= 0.01)
  1134. {
  1135. $price_arr['card_price'] = $option_cardprice_arr['card_price'];
  1136. }else{
  1137. $price_arr['card_price'] = $goods_info['card_price'];
  1138. }
  1139. }
  1140. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy')->where( array('goods_id' => $goods_id ) )->find();
  1141. $price_arr['is_mb_level_buy'] = 0;
  1142. //新增的会员折扣 begin
  1143. if($goods_info['type'] !='pin')
  1144. {
  1145. if($member_id >0 && $goods_common['is_mb_level_buy'] == 1 )
  1146. {
  1147. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
  1148. if( $member_info['level_id'] > 0)
  1149. {
  1150. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  1151. $vipprice = round( ($price_arr['price'] * $member_level_info['discount']) /100 ,2);
  1152. $vaipdanprice = round( ($price_arr['danprice'] * $member_level_info['discount']) /100 ,2);
  1153. $price_arr['levelprice'] = sprintf('%.2f', $vipprice );
  1154. $price_arr['leveldanprice'] = sprintf('%.2f', $vaipdanprice );
  1155. }else{
  1156. $price_arr['levelprice'] = sprintf('%.2f', $price_arr['price'] );
  1157. $price_arr['leveldanprice'] = sprintf('%.2f', $price_arr['danprice'] );
  1158. }
  1159. $price_arr['is_mb_level_buy'] = 1;
  1160. }
  1161. }
  1162. return $price_arr;
  1163. }
  1164. public function get_goods_description($goods_id,$fields='*') {
  1165. $goods_info = M('goods_description')->field($fields)->where( array('goods_id' => $goods_id) )->find();
  1166. return $goods_info;
  1167. }
  1168. public function get_goods_options($goods_id,$member_id =0)
  1169. {
  1170. $result = array();
  1171. $goods_option_name = array();
  1172. $goods_option_data = array();
  1173. $goods_info = M('lionfish_comshop_goods')->field('goodsname,productprice')->where( array('id' => $goods_id ) )->find();
  1174. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy')->where( array('goods_id' => $goods_id ) )->find();
  1175. $goods_option_query = M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id) )->select();
  1176. $sku_goods_image = '';
  1177. $good_image = $this->get_goods_images($goods_id);
  1178. if( !empty($good_image) )
  1179. {
  1180. $sku_goods_image = tomedia($good_image['image']);
  1181. }
  1182. if( !empty($goods_option_query) )
  1183. {
  1184. $option_item_image = array();
  1185. foreach ($goods_option_query as $goods_option) {
  1186. $goods_option_value_data = array();
  1187. $goods_option_value_query = M('lionfish_comshop_goods_option_item')->where( array('goods_option_id' => $goods_option['id']) )->order('displayorder desc,id desc')->select();
  1188. foreach ($goods_option_value_query as $goods_option_value) {
  1189. $goods_option_value_data[] = array(
  1190. 'goods_option_value_id' => $goods_option_value['id'],
  1191. 'option_value_id' => $goods_option_value['id'],
  1192. 'name' =>$goods_option_value['title'],
  1193. 'image' =>isset($goods_option_value['thumb']) ? tomedia($goods_option_value['thumb']) : '',
  1194. );
  1195. if(!empty($goods_option_value['thumb']))
  1196. {
  1197. $option_item_image[$goods_option_value['id']] = tomedia($goods_option_value['thumb']);
  1198. }
  1199. }
  1200. $goods_option_name[] = $goods_option['title'];
  1201. $goods_option_data[] = array(
  1202. 'goods_option_id' => $goods_option['id'],
  1203. 'option_id' => $goods_option['id'],
  1204. 'name' => $goods_option['title'],
  1205. 'option_value' => $goods_option_value_data,
  1206. );
  1207. }
  1208. $result['list'] = $goods_option_data;
  1209. $result['name'] = $goods_option_name;
  1210. if($member_id >0)
  1211. {
  1212. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
  1213. if( $member_info['level_id'] > 0)
  1214. {
  1215. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  1216. }
  1217. }
  1218. $mult_item_list = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id) )->select();
  1219. $sku_mu_list = array();
  1220. foreach($mult_item_list as $val)
  1221. {
  1222. //goodsname,productprice
  1223. $val['levelprice'] = $val['marketprice'];
  1224. if($member_id >0 && $goods_common['is_mb_level_buy'] == 1)
  1225. {
  1226. if( $member_info['level_id'] > 0)
  1227. {
  1228. $val['levelprice'] = round( ($val['marketprice'] * $member_level_info['discount']) /100 ,2);
  1229. $val['pinprice'] = round( ($val['pinprice'] * $member_level_info['discount']) /100 ,2);
  1230. }
  1231. }
  1232. $tmp_arr = array();
  1233. $tmp_arr['spec'] = $val['title'];
  1234. $tmp_arr['canBuyNum'] = $val['stock'];
  1235. $tmp_arr['spuName'] = $goods_info['goodsname'];
  1236. $tmp_arr['actPrice'] = explode('.', $val['marketprice']);
  1237. $tmp_arr['marketPrice'] = explode('.', $val['productprice']);
  1238. $tmp_arr['pinprice'] = explode('.', $val['pinprice']);
  1239. $tmp_arr['card_price'] = explode('.', $val['card_price']);
  1240. $tmp_arr['levelprice'] = explode('.', $val['levelprice']);
  1241. $tmp_arr['option_item_ids'] = $val['option_item_ids'];
  1242. $tmp_arr['stock'] = $val['stock'];
  1243. $ids_option = explode('_', $val['option_item_ids']);
  1244. $img = '';
  1245. foreach($ids_option as $vv)
  1246. {
  1247. if(isset($option_item_image[$vv]))
  1248. {
  1249. $img = $option_item_image[$vv];
  1250. break;
  1251. }
  1252. }
  1253. if( empty($img) )
  1254. {
  1255. $img = $sku_goods_image;
  1256. }
  1257. $tmp_arr['skuImage'] = $img;
  1258. $sku_mu_list[$val['option_item_ids']] = $tmp_arr;
  1259. }
  1260. $result['sku_mu_list'] = $sku_mu_list;
  1261. //array('spec' => 'xl','canBuyNum' => 100,'spuName' => 1, 'actPrice' => array(1,2), 'marketPrice' => array(2,3),'skuImage' => tomedia($good_image['image'])),
  1262. }
  1263. return $result;
  1264. }
  1265. /**
  1266. 判断规格是否失效
  1267. **/
  1268. public function get_goods_option_can_buy( $goods_id, $sku_str )
  1269. {
  1270. if( empty($sku_str) )
  1271. {
  1272. return 1;
  1273. }else{
  1274. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' =>$sku_str,'goods_id' => $goods_id ) )->find();
  1275. if( empty($goods_option_mult_value) )
  1276. {
  1277. return 0;
  1278. }else{
  1279. return 1;
  1280. }
  1281. }
  1282. }
  1283. public function get_goods_time_can_buy($goods_id)
  1284. {
  1285. $goods_info = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
  1286. if( $goods_info['total'] <= 0 || $goods_info['grounding'] != 1)
  1287. {
  1288. return 0;
  1289. }
  1290. $goods_info = M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->find();
  1291. $now_time = time();
  1292. if( $now_time<$goods_info['begin_time'] || $now_time > $goods_info['end_time'])
  1293. {
  1294. return 0;
  1295. }else{
  1296. return 1;
  1297. }
  1298. }
  1299. /**
  1300. 获取商品数量
  1301. **/
  1302. public function get_goods_count($where = '',$uniacid = 0)
  1303. {
  1304. $total = M('lionfish_comshop_goods')->where("1 ".$where)->count();
  1305. return $total;
  1306. }
  1307. /**
  1308. 给商品扣除库存
  1309. **/
  1310. /**
  1311. 扣除/增加商品多规格库存
  1312. 1扣除, 2 增加
  1313. **/
  1314. public function del_goods_mult_option_quantity($order_id,$option,$goods_id,$quantity,$type='1')
  1315. {
  1316. $tp_goods = M('lionfish_comshop_goods')->field('total as quantity')->where( array('id' => $goods_id) )->find();
  1317. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id, 'goods_id' => $goods_id ) )->find();
  1318. $option_list = M('lionfish_comshop_order_option')->where( array('order_id' => $order_id,'order_goods_id' => $goods_id) )->find();
  1319. if($type == 1)
  1320. {
  1321. $quantity_order_data = array();
  1322. $quantity_order_data['order_id'] = $order_id;
  1323. $quantity_order_data['goods_id'] = $goods_id;
  1324. $quantity_order_data['rela_goodsoption_value_id'] = $option;
  1325. $quantity_order_data['quantity'] = $quantity;
  1326. $quantity_order_data['type'] = 0;
  1327. $quantity_order_data['last_quantity'] = $tp_goods['quantity'];
  1328. $quantity_order_data['addtime'] = time();
  1329. M('lionfish_comshop_order_quantity_order')->add($quantity_order_data);
  1330. //扣除库存
  1331. $up_total_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET total = (total - " . (int)$quantity . ") where id={$goods_id} ";
  1332. M()->execute($up_total_sql);
  1333. //销量增加
  1334. $up_seller_count_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET seller_count = (seller_count + " . (int)$quantity . ") WHERE id = {$goods_id}";
  1335. M()->execute($up_seller_count_sql);
  1336. //释放出reids占位,还有取消订单也要释放出redis占位---begin
  1337. $order_info = M('lionfish_comshop_order')->field('member_id')->where( array('order_id' => $order_id) )->find();
  1338. $redis_has_add_list = array();
  1339. $redis_has_add_list[] = array('member_id' => $order_info['member_id'], 'goods_id' => $goods_id, 'sku_str' => $option );
  1340. //D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  1341. //D('Seller/Redisorder')->cancle_goods_buy_user($redis_has_add_list);
  1342. //--------end
  1343. } else if($type == 2){
  1344. $quantity_order_data = array();
  1345. $quantity_order_data['order_id'] = $order_id;
  1346. $quantity_order_data['goods_id'] = $goods_id;
  1347. $quantity_order_data['rela_goodsoption_value_id'] = $option;
  1348. $quantity_order_data['quantity'] = $quantity;
  1349. $quantity_order_data['type'] = 1;
  1350. $quantity_order_data['last_quantity'] = $tp_goods['quantity'];
  1351. $quantity_order_data['addtime'] = time();
  1352. M('lionfish_comshop_order_quantity_order')->add($quantity_order_data);
  1353. //增加库存
  1354. $up_total_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET total = (total + " . (int)$quantity . ") where id={$goods_id} ";
  1355. M()->execute($up_total_sql);
  1356. //销量减少
  1357. $up_seller_count_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET seller_count = (seller_count - " . (int)$quantity . ") WHERE id = {$goods_id}";
  1358. M()->execute($up_seller_count_sql);
  1359. D('Seller/Redisorder')->bu_goods_quantity($goods_id,$quantity);
  1360. }
  1361. if(!empty($option))
  1362. {
  1363. if($type == 1)
  1364. {
  1365. $up_sku_total_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods_option_item_value SET stock = (stock - " . (int)$quantity . ") where goods_id={$goods_id} and option_item_ids='{$option}' ";
  1366. M()->execute($up_sku_total_sql);
  1367. } else if($type ==2){
  1368. $up_sku_total_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods_option_item_value SET stock = (stock + " . (int)$quantity . ") where goods_id={$goods_id} and option_item_ids='{$option}' ";
  1369. M()->execute($up_sku_total_sql);
  1370. D('Seller/Redisorder')->bu_goods_sku_quantity($goods_id,$quantity, $option);
  1371. }
  1372. }
  1373. //D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  1374. }
  1375. /**
  1376. 获取比较详细混合的商品信息
  1377. 可能会包含到分佣的情况
  1378. **/
  1379. public function get_goods_mixinfo($goods_id)
  1380. {
  1381. $need_data = array();
  1382. $goods_info = M('lionfish_comshop_goods')->field('credit as points,type,codes as model')->where( array('id' => $goods_id) )->find();
  1383. $commiss_info = M('lionfish_comshop_good_commiss')->where( array('goods_id' => $goods_id) )->find();
  1384. if( !empty($commiss_info) )
  1385. {
  1386. //涉及到会员分销等级,先放着
  1387. }else{
  1388. $goods_info['nocommission'] = 0;
  1389. $goods_info['hascommission'] = 0;
  1390. }
  1391. /**M('goods')->field(
  1392. 'points,commiss_fen_one_disc,
  1393. commiss_fen_two_disc,commiss_fen_three_disc,commiss_three_dan_disc,commiss_two_dan_disc,
  1394. commiss_one_dan_disc,store_id,type,model,image'
  1395. )->where( array('goods_id' => $goods_id) )->find();
  1396. **/
  1397. }
  1398. }