PingoodsModel.class.php 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569
  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. //index_sort_method 0 置顶排序 1 排序大小排序(从大到小)
  12. $index_sort_method = D('Home/Front')->get_config_by_name('index_sort_method' );
  13. if(empty($index_sort_method)){
  14. $sql_pingoods = "select {$fields} from "
  15. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc
  16. where {$where} and g.id=gc.goods_id order by g.istop DESC, g.settoptime DESC,g.id desc limit {$offset},{$perpage} ";
  17. }else{
  18. $sql_pingoods = "select {$fields} from "
  19. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc
  20. where {$where} and g.id=gc.goods_id order by g.index_sort desc,g.id desc limit {$offset},{$perpage} ";
  21. }
  22. $list_pingoods = M()->query($sql_pingoods);
  23. return $list_pingoods;
  24. }
  25. 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 ')
  26. {
  27. $inner_join ="";
  28. if( $head_id > 0 )
  29. {
  30. $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}) ) ";
  31. }
  32. if( !empty($gid) )
  33. {
  34. $gd_cate_sql = " select goods_id from ".C('DB_PREFIX')."lionfish_comshop_goods_to_category where cate_id in ({$gid}) ";
  35. $cate_all = M()->query($gd_cate_sql );
  36. $cate_goods_ids = array();
  37. if( !empty($cate_all) )
  38. {
  39. foreach($cate_all as $val)
  40. {
  41. $cate_goods_ids[] = $val['goods_id'];
  42. }
  43. $cate_goods_str = implode(',', $cate_goods_ids);
  44. $where .= " and g.id in ({$cate_goods_str}) ";
  45. }else{
  46. $where .= " and g.id in (0) ";
  47. }
  48. }
  49. $sql_pingoods = "select {$fields} from "
  50. .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc {$inner_join}
  51. where {$where} and g.id=gc.goods_id order by {$order} limit {$offset},{$perpage} ";
  52. //dump($sql_pingoods);
  53. $list_pingoods = M()->query($sql_pingoods);
  54. return $list_pingoods;
  55. }
  56. //begin index_share_qrcode
  57. /**
  58. 分销商海报
  59. **/
  60. public function get_commission_index_share_image($community_id,$wepro_qrcode,$avatar,$nickname)
  61. {
  62. $send_path = "Uploads/image/".date('Y-m-d')."/haibao_goods/";
  63. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  64. RecursiveMkdir($image_dir);
  65. $bg_img = ROOT_PATH."/static/images/index_share_bg.jpg";
  66. //index_share_qrcode_bg
  67. $index_share_qrcode_bg = D('Home/Front')->get_config_by_name('distribution_img_src');
  68. if( !empty($index_share_qrcode_bg) )
  69. {
  70. $bg_img = ROOT_PATH.'Uploads/image/' . $index_share_qrcode_bg;
  71. }
  72. $dst = imagecreatefromstring(file_get_contents($bg_img));
  73. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  74. $ttf_path = ROOT_PATH."/static/fonts/simhei.ttf";
  75. $msyh_path = ROOT_PATH."/static/fonts/msyh.ttf";
  76. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  77. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  78. //打上文字
  79. $black = imagecolorallocate($dst, 20,20,20);//黑色
  80. $a1a1a1 = imagecolorallocate($dst, 26,26,26);//黑色
  81. $red = imagecolorallocate($dst, 237, 48, 43); //红色 201 55 49
  82. $huise = imagecolorallocate($dst, 159, 159, 159); //灰色 159 159 159
  83. $fense = imagecolorallocate($dst, 248, 136, 161); //粉色 248 136 161
  84. $gray1 = imagecolorallocate($dst, 51, 51, 51); //#333 51, 51, 51
  85. $gray2 = imagecolorallocate($dst, 102, 102, 6); //#666 102, 102, 6
  86. $gray3 = imagecolorallocate($dst, 153, 153, 153); //#999 153, 153, 153
  87. $gray4 = imagecolorallocate($dst, 116, 116, 116); //#999 116, 116, 116
  88. $red_2 = imagecolorallocate($dst, 223, 21, 21); //#999 223, 21, 21
  89. $chengse = imagecolorallocate($dst, 252, 74, 74); //#999
  90. $distribution_username_left = D('Home/Front')->get_config_by_name('distribution_username_left');
  91. $distribution_username_top = D('Home/Front')->get_config_by_name('distribution_username_top');
  92. $distribution_username_left = empty($distribution_username_left) ? 0: $distribution_username_left * 2;
  93. $distribution_username_top = empty($distribution_username_top) ? 0: $distribution_username_top * 2 ;
  94. $avatar = 'Uploads/image/'.$avatar;
  95. $commiss_nickname_rgb = D('Home/Front')->get_config_by_name('commiss_nickname_rgb');
  96. $rgb_arr = array('r' => 248,'g' => 136,'b' => 161);
  97. if( !empty($commiss_nickname_rgb) )
  98. {
  99. $rgb_arr = $this->hex2rgb($commiss_nickname_rgb);
  100. }
  101. $col = imagecolorallocate($dst,$rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b']);
  102. //$col = imagecolorallocate($dst,248, 136, 161);
  103. imagefttext($dst, 20, 0, $distribution_username_left, $distribution_username_top, $col, $pingfang_med_path, $nickname );
  104. list($avatar_img_img_w, $avatar_img_img_h, $avatar_img_img_type) = getimagesize(ROOT_PATH.$avatar);
  105. $avatar_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$avatar));
  106. if (imageistruecolor($avatar_img_src))
  107. imagetruecolortopalette($avatar_img_src, false, 65535);
  108. $distribution_avatar_left = D('Home/Front')->get_config_by_name('distribution_avatar_left');
  109. $distribution_avatar_top = D('Home/Front')->get_config_by_name('distribution_avatar_top');
  110. if( empty($distribution_avatar_left) )
  111. {
  112. $distribution_avatar_left = 0;
  113. }else{
  114. $distribution_avatar_left = $distribution_avatar_left * 2;
  115. }
  116. if( empty($distribution_avatar_top) )
  117. {
  118. $distribution_avatar_top = 0;
  119. }else{
  120. $distribution_avatar_top = $distribution_avatar_top * 2;
  121. }
  122. imagecopy($dst, $avatar_img_src, $distribution_avatar_left, $distribution_avatar_top, 0, 0, $avatar_img_img_w, $avatar_img_img_h);
  123. //wepro_qrcode
  124. $distribution_qrcodes_left = D('Home/Front')->get_config_by_name('distribution_qrcodes_left');
  125. $distribution_qrcodes_top = D('Home/Front')->get_config_by_name('distribution_qrcodes_top');
  126. if( empty($distribution_qrcodes_left) )
  127. {
  128. $distribution_qrcodes_left = 0;
  129. }else{
  130. $distribution_qrcodes_left = $distribution_qrcodes_left * 2;
  131. }
  132. if( empty($distribution_qrcodes_top) )
  133. {
  134. $distribution_qrcodes_top = 0;
  135. }else{
  136. $distribution_qrcodes_top = $distribution_qrcodes_top * 2;
  137. }
  138. $thumb_goods_img = $wepro_qrcode;
  139. $wepro_qrcode_new = str_replace('Uploads/image/','', $thumb_goods_img);
  140. $thumb_goods_img = resize($wepro_qrcode_new,180,180);
  141. list($thumb_goods_img_w, $thumb_goods_img_h, $thumb_goods_img_type) = getimagesize(ROOT_PATH.$thumb_goods_img);
  142. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  143. $thumb_goods_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  144. if (imageistruecolor($thumb_goods_img_src))
  145. imagetruecolortopalette($thumb_goods_img_src, false, 65535);
  146. imagecopy($dst, $goods_src, $distribution_qrcodes_left, $distribution_qrcodes_top, 0, 0, $thumb_goods_img_w, $thumb_goods_img_h);
  147. /**
  148. **/
  149. $send_path = "Uploads/image/".date('Y-m-d')."/haibao_goods/";
  150. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  151. RecursiveMkdir($image_dir);
  152. $last_img = $image_dir;
  153. $last_img_name = "last_index_".md5( time().$community_id.$wepro_qrcode.mt_rand(1,999)).'';
  154. switch ($dst_type) {
  155. case 1://GIF
  156. $last_img_name .= '.gif';
  157. //header('Content-Type: image/gif');
  158. imagegif($dst, $last_img.$last_img_name);
  159. break;
  160. case 2://JPG
  161. $last_img_name .= '.jpg';
  162. //header('Content-Type: image/jpeg');
  163. imagejpeg($dst, $last_img.$last_img_name);
  164. break;
  165. case 3://PNG
  166. $last_img_name .= '.png';
  167. //header('Content-Type: image/png');
  168. imagepng($dst, $last_img.$last_img_name);
  169. break;
  170. default:
  171. break;
  172. }
  173. imagedestroy($dst);
  174. $fullname = ROOT_PATH.$send_path.$last_img_name;
  175. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  176. if( $attachment_type_arr['value'] == 1 )
  177. {
  178. save_image_to_qiniu($fullname,$send_path.$last_img_name);
  179. }else if( $attachment_type_arr['value'] == 2 ){
  180. save_image_to_alioss($fullname,$send_path.$last_img_name);
  181. }else if( $attachment_type_arr['value'] == 3 ){
  182. save_image_to_txyun($fullname,$send_path.$last_img_name);
  183. }
  184. $result = array('full_path' => date('Y-m-d')."/haibao_goods/".$last_img_name,'need_path' => date('Y-m-d')."/haibao_goods/".$last_img_name);
  185. return $result;
  186. }
  187. public function get_weindex_share_image($community_id,$wepro_qrcode,$avatar , $member_id)
  188. {
  189. $community_info = D('Home/Front')->get_community_byid($community_id);
  190. $goods_ids_arr = M()->query('SELECT goods_id FROM ' . C('DB_PREFIX') . "lionfish_community_head_goods
  191. WHERE head_id=".$community_id." order by id desc ");
  192. $ids_arr = array();
  193. foreach($goods_ids_arr as $val){
  194. $ids_arr[] = $val['goods_id'];
  195. }
  196. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  197. WHERE is_all_sale=1 ");
  198. if( !empty($goods_ids_nolimit_arr) )
  199. {
  200. foreach($goods_ids_nolimit_arr as $val){
  201. $ids_arr[] = $val['id'];
  202. }
  203. }
  204. $ids_str = implode(',',$ids_arr);
  205. $where = " g.grounding =1 ";
  206. if( !empty($ids_str) )
  207. {
  208. $where .= " and g.id in ({$ids_str})";
  209. } else{
  210. $where .= " and 0 ";
  211. }
  212. $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);
  213. $send_path = "Uploads/image/".date('Y-m-d')."/";
  214. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  215. RecursiveMkdir($image_dir);
  216. $bg_img = ROOT_PATH."/static/images/index_share_bg.jpg";
  217. $need_delete_image_arr = array();
  218. //index_share_qrcode_bg
  219. $index_share_qrcode_bg = D('Home/Front')->get_config_by_name('index_share_qrcode_bg');
  220. if( !empty($index_share_qrcode_bg) )
  221. {
  222. $bg_img = ROOT_PATH.'Uploads/image/' . $index_share_qrcode_bg;
  223. }
  224. $dst = imagecreatefromjpeg ($bg_img);
  225. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  226. $ttf_path = ROOT_PATH."/static/fonts/simhei.ttf";
  227. $msyh_path = ROOT_PATH."/static/fonts/msyh.ttf";
  228. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  229. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  230. //打上文字
  231. $black = imagecolorallocate($dst, 20,20,20);//黑色
  232. $a1a1a1 = imagecolorallocate($dst, 26,26,26);//黑色
  233. $red = imagecolorallocate($dst, 237, 48, 43); //红色 201 55 49
  234. $huise = imagecolorallocate($dst, 159, 159, 159); //灰色 159 159 159
  235. $fense = imagecolorallocate($dst, 248, 136, 161); //粉色 248 136 161
  236. $gray1 = imagecolorallocate($dst, 51, 51, 51); //#333 51, 51, 51
  237. $gray2 = imagecolorallocate($dst, 102, 102, 6); //#666 102, 102, 6
  238. $gray3 = imagecolorallocate($dst, 153, 153, 153); //#999 153, 153, 153
  239. $gray4 = imagecolorallocate($dst, 116, 116, 116); //#999 116, 116, 116
  240. $red_2 = imagecolorallocate($dst, 223, 21, 21); //#999 223, 21, 21
  241. //开始在图上画物体
  242. imagefttext($dst, 29, 0, 254, 228, $chengse, $pingfang_med_path, date('m月d日').'爆款');
  243. // 小区名称
  244. $haibao_group_name = D('Home/Front')->get_config_by_name('haibao_group_name');
  245. if( empty($haibao_group_name) )
  246. {
  247. $haibao_group_name = '小区团长:';
  248. }
  249. imagefttext($dst, 20, 0, 32, 1130, $chengse, $pingfang_med_path, $haibao_group_name);
  250. $group_name_len = mb_strlen($haibao_group_name, 'utf-8');
  251. $group_left = 0;
  252. if($group_name_len>4) {
  253. $group_left = ($group_name_len-4) * 24;
  254. }
  255. // 头像
  256. $avatar = str_replace('Uploads/image/','',$avatar);
  257. $avatar_img = resize($avatar,30,30);
  258. list($avatar_img_img_w, $avatar_img_img_h, $avatar_img_img_type) = getimagesize(ROOT_PATH.$avatar_img);
  259. $avatar_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$avatar_img));
  260. if (imageistruecolor($avatar_img_src))
  261. imagetruecolortopalette($avatar_img_src, false, 65535);
  262. imagecopy($dst, $avatar_img_src, 162+$group_left, 1105, 0, 0, $avatar_img_img_w, $avatar_img_img_h);
  263. $count = mb_strlen($community_info['disUserName'],'utf-8');
  264. $xin_str = '';
  265. for($i=1;$i<$count;$i++)
  266. {
  267. $xin_str .="*";
  268. }
  269. if($count>2)
  270. {
  271. $xin_str = '*'.mb_substr($community_info['disUserName'],-1,1,'utf-8');
  272. }
  273. imagefttext($dst, 20, 0, 198+$group_left, 1130, $chengse, $pingfang_med_path, mb_substr($community_info['disUserName'],0,1,'utf-8').$xin_str );
  274. $modify_index_share_time = D('Home/Front')->get_config_by_name('modify_index_share_time');
  275. if(empty($modify_index_share_time))
  276. {
  277. $modify_index_share_time = date('H:00:00');
  278. }
  279. imagefttext($dst, 20, 0, 32, 1170, $chengse, $pingfang_med_path, '抢购时间:'.date('Y-m-d').' '.$modify_index_share_time);
  280. $open_danhead_model = D('Home/Front')->get_config_by_name('open_danhead_model');
  281. if ($open_danhead_model!=1) {
  282. // 团长地址
  283. $fullAddress = $community_info['fullAddress'];
  284. $need_fullAddress = mb_substr($fullAddress,0,12,'utf-8')."\r\n";
  285. $need_fullAddress2 = mb_substr($fullAddress,12,11,'utf-8');
  286. //.'...'mb_strlen(
  287. if( mb_strlen($fullAddress,'utf-8') > 23)
  288. {
  289. $need_fullAddress2 .= '...';
  290. }
  291. imagefttext($dst, 20, 0, 32, 1203, $chengse, $pingfang_med_path, '提货地址:'.$need_fullAddress);
  292. imagefttext($dst, 20, 0, 160, 1233, $chengse, $pingfang_med_path, $need_fullAddress2);
  293. }
  294. $i = 1;
  295. foreach($community_goods_list as $goods)
  296. {
  297. $skuImage = '';
  298. $good_image = $this->get_goods_images($goods['id']);
  299. if( empty($good_image) )
  300. {
  301. continue;
  302. }
  303. $skuImage = $good_image['image'];
  304. $thumb_goods_img = resize($skuImage,138,138);
  305. $need_delete_image_arr[] = ROOT_PATH.$thumb_goods_img;
  306. list($thumb_goods_img_w, $thumb_goods_img_h, $thumb_goods_img_type) = getimagesize(ROOT_PATH.$thumb_goods_img);
  307. $thumb_goods_img_src = $this->radius_img(ROOT_PATH.$thumb_goods_img, 138/2,3);
  308. if($thumb_goods_img_type == 'jpeg' || $thumb_goods_img_type == 'jpg')
  309. {
  310. $thumb_goods_img .= '.jpg';
  311. imagejpeg($thumb_goods_img_src, ROOT_PATH.$thumb_goods_img);
  312. }else{
  313. $thumb_goods_img .= '.png';
  314. imagepng($thumb_goods_img_src, ROOT_PATH.$thumb_goods_img);
  315. }
  316. imagedestroy($thumb_goods_img_src);
  317. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  318. if (imageistruecolor($goods_src))
  319. imagetruecolortopalette($goods_src, false, 65535);
  320. list($goods_src_w, $goods_src_h) = getimagesize(ROOT_PATH.$thumb_goods_img);
  321. $del_x = ($i % 2) == 0 ? 326 : 0;
  322. $del_y = ( ceil($i/2)-1) * 196;
  323. imagecopymerge($dst, $goods_src, 58+$del_x, 278+$del_y, 0, 0, $goods_src_w, $goods_src_h, 100);
  324. $price_arr = $this->get_goods_price($goods['id'] , $member_id);
  325. $price = $price_arr['price'];
  326. imagedestroy($goods_src);
  327. $goods_title = $goods['goodsname'];
  328. $need_goods_title = mb_substr($goods_title,0,6,'utf-8')."\r\n";
  329. $need_goods_title .= mb_substr($goods_title,6,5,'utf-8');
  330. //.'...'mb_strlen(
  331. if( mb_strlen($goods_title,'utf-8') > 11)
  332. {
  333. $need_goods_title .= '...';
  334. }
  335. imagefttext($dst, 18, 0, 208+$del_x, 315+$del_y, $gray1, $pingfang_med_path, $need_goods_title );
  336. imagefttext($dst, 14, 0, 208+$del_x, 375+$del_y, $gray4, $pingfang_med_path, '¥'.$goods['productprice'] );
  337. $size_12 = strlen($goods['productprice']);
  338. $pos = 225 + intval(13 * ($size_12 -1) -3 );
  339. imageline($dst, 225+$del_x, 368+$del_y, $pos+$del_x, 368+$del_y, $gray3); //画线
  340. imagefttext($dst, 18, 0, 208+$del_x, 410+$del_y, $red_2, $pingfang_path, '¥'.$price );
  341. //break;
  342. $i++;
  343. }
  344. $thumb_goods_img = $wepro_qrcode;
  345. $need_delete_image_arr[] = ROOT_PATH.$thumb_goods_img;
  346. $wepro_qrcode = str_replace('Uploads/image/','',$wepro_qrcode);
  347. $thumb_goods_img = resize($wepro_qrcode,180,180);
  348. list($thumb_goods_img_w, $thumb_goods_img_h, $thumb_goods_img_type) = getimagesize(ROOT_PATH.$thumb_goods_img);
  349. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  350. $thumb_goods_img_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  351. if (imageistruecolor($thumb_goods_img_src))
  352. imagetruecolortopalette($thumb_goods_img_src, false, 65535);
  353. imagecopy($dst, $goods_src, 516, 1098, 0, 0, $thumb_goods_img_w, $thumb_goods_img_h);
  354. //结束图上画物体
  355. $last_img = $image_dir;
  356. $last_img_name = "last_index_".md5( time().$community_id.mt_rand(1,999)).'';
  357. switch ($dst_type) {
  358. case 1://GIF
  359. $last_img_name .= '.gif';
  360. header('Content-Type: image/gif');
  361. imagegif($dst, $last_img.$last_img_name);
  362. break;
  363. case 2://JPG
  364. $last_img_name .= '.jpg';
  365. //header('Content-Type: image/jpeg');
  366. imagejpeg($dst, $last_img.$last_img_name);
  367. break;
  368. case 3://PNG
  369. $last_img_name .= '.png';
  370. header('Content-Type: image/png');
  371. imagepng($dst, $last_img.$last_img_name);
  372. break;
  373. default:
  374. break;
  375. }
  376. imagedestroy($dst);
  377. //imagedestroy($goods_src);
  378. $result = array('full_path' => $send_path.$last_img_name,'need_path' => $send_path.$last_img_name);
  379. foreach( $need_delete_image_arr as $del_img )
  380. {
  381. @unlink($del_img);
  382. }
  383. return $result;
  384. }
  385. public function check_qiniu_image($goods_img_info_image)
  386. {
  387. global $_W;
  388. global $_GPC;
  389. if (!empty($_W['setting']['remote']['type']))
  390. {
  391. $header = array(
  392. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  393. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  394. 'Accept-Encoding: gzip, deflate',);
  395. $goods_img = tomedia( $goods_img_info_image);
  396. $curl = curl_init();
  397. curl_setopt($curl, CURLOPT_URL, $goods_img);
  398. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  399. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  400. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  401. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  402. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  403. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  404. $data = curl_exec($curl);
  405. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  406. curl_close($curl);
  407. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  408. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  409. }
  410. $img_content=$imgBase64Code;//图片内容
  411. //echo $img_content;exit;
  412. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  413. {
  414. $type = $result[2];//得到图片类型png?jpg?gif?
  415. $send_path = "images/".date('Y-m-d')."/";
  416. $image_dir = ATTACHMENT_ROOT.$send_path; //上传文件路径
  417. load()->func('file');
  418. mkdirs($image_dir);
  419. $new_file = md5($goods_img).".{$type}";
  420. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  421. $goods_img_info_image = $send_path.$new_file;
  422. }
  423. }
  424. return $goods_img_info_image;
  425. }
  426. public function get_goods_tags($label_id)
  427. {
  428. $tag_info = M('lionfish_comshop_goods_tags')->field('id,tagname,type,tagcontent')->where( array('id' => $label_id) )->find();
  429. return $tag_info;
  430. }
  431. public function get_min_time(){
  432. global $_W;
  433. global $_GPC;
  434. $now_time = time();
  435. $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 and g.type = "normal" ';
  436. $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}";
  437. $rushtime_arr = M()->query($sql);
  438. $rushtime = $rushtime_arr[0];
  439. return $rushtime['rushtime'];
  440. }
  441. /**
  442. * 获取即将抢购商品总数
  443. * @return [string] [总数]
  444. */
  445. public function get_comming_goods_count(){
  446. $now_time = time();
  447. $where .= " begin_time > {$now_time} ";
  448. $count = M('lionfish_comshop_good_common')->where( " begin_time > {$now_time} " )->count();
  449. return $count;
  450. }
  451. //end index_share_qrcode
  452. public function get_weshare_image($goods_id , $member_id)
  453. {
  454. $goods_info = M('lionfish_comshop_goods')->field('goodsname,price,productprice,sales,seller_count,total,type')->where( array('id' => $goods_id) )->find();
  455. $goods_img_info = $this->get_goods_images($goods_id);
  456. $goods_img = ROOT_PATH.'Uploads/image/' . $goods_img_info['image'];
  457. $goods_price = $this->get_goods_price($goods_id , $member_id);
  458. $goods_price['market_price'] = $goods_info['productprice'];
  459. $goods_title = $goods_info['goodsname'];
  460. $seller_count = $goods_info['seller_count'] + $goods_info['sales'];
  461. $quantity = $goods_info['total'];
  462. if($goods_info['type']=='integral') {
  463. $goods_price['price'] = round($goods_price['price'], 0);
  464. $goods_price['market_price'] = round($goods_price['market_price'], 0);
  465. }
  466. $need_img = $this->_get_compare_zan_img($goods_img_info['image'], $goods_title, $goods_price,$seller_count,$quantity,$goods_info['type']);
  467. //贴上二维码图
  468. $up_data = array();
  469. $up_data['wepro_qrcode_image'] = $need_img['need_path'];
  470. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save( $up_data );
  471. return true;
  472. }
  473. function radius_img($imgpath = './t.png', $radius = 15, $color=1) {
  474. $ext = pathinfo($imgpath);
  475. $src_img = null;
  476. switch ($ext['extension']) {
  477. case 'jpg':
  478. $src_img = imagecreatefromjpeg($imgpath);
  479. break;
  480. case 'jpeg':
  481. $src_img = imagecreatefromjpeg($imgpath);
  482. break;
  483. case 'png':
  484. $src_img = imagecreatefrompng($imgpath);
  485. break;
  486. }
  487. $wh = getimagesize($imgpath);
  488. $w = $wh[0];
  489. $h = $wh[1];
  490. // $radius = $radius == 0 ? (min($w, $h) / 2) : $radius;
  491. $img = imagecreatetruecolor($w, $h);
  492. //这一句一定要有
  493. imagesavealpha($img, true);
  494. //拾取一个完全透明的颜色,最后一个参数127为全透明
  495. //拾取一个完全透明的颜色,最后一个参数127为全透明 int $red , int $green , int $blu
  496. if($color == 1)
  497. {
  498. $bg = imagecolorallocatealpha($img, 244, 91, 86, 127);
  499. }else if($color == 2){
  500. //
  501. $avatar_rgb = D('Home/Front')->get_config_by_name('avatar_rgb' );
  502. if( !empty($avatar_rgb) )
  503. {
  504. $rgb_arr = $this->hex2rgb($avatar_rgb);
  505. $bg = imagecolorallocatealpha($img, $rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b'], 127);
  506. }else{
  507. $bg = imagecolorallocatealpha($img, 255, 245, 98, 127);
  508. }
  509. }else if($color == 3){
  510. $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
  511. }else if($color == 4){
  512. $bg = imagecolorallocatealpha($img, 252, 243, 10, 127);
  513. }else if($color == 5){
  514. $avatar_rgb = D('Home/Front')->get_config_by_name('commiss_avatar_rgb' );
  515. if( !empty($avatar_rgb) )
  516. {
  517. $rgb_arr = $this->hex2rgb($avatar_rgb);
  518. $bg = imagecolorallocatealpha($img, $rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b'], 127);
  519. }else{
  520. $bg = imagecolorallocatealpha($img, 255, 245, 98, 127);
  521. }
  522. } else if($color == 6){
  523. // 详情页海报
  524. $avatar_rgb = D('Home/Front')->get_config_by_name('goods_avatar_rgb' );
  525. if( !empty($avatar_rgb) )
  526. {
  527. $rgb_arr = $this->hex2rgb($avatar_rgb);
  528. $bg = imagecolorallocatealpha($img, $rgb_arr['r'], $rgb_arr['g'], $rgb_arr['b'], 127);
  529. }else{
  530. $bg = imagecolorallocatealpha($img, 255, 245, 98, 127);
  531. }
  532. }
  533. imagefill($img, 0, 0, $bg);
  534. $r = $radius; //圆 角半径
  535. for ($x = 0; $x < $w; $x++) {
  536. for ($y = 0; $y < $h; $y++) {
  537. $rgbColor = imagecolorat($src_img, $x, $y);
  538. if (($x >= $radius && $x <= ($w - $radius)) || ($y >= $radius && $y <= ($h - $radius))) {
  539. //不在四角的范围内,直接画
  540. imagesetpixel($img, $x, $y, $rgbColor);
  541. } else {
  542. //在四角的范围内选择画
  543. //上左
  544. $y_x = $r; //圆心X坐标
  545. $y_y = $r; //圆心Y坐标
  546. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  547. imagesetpixel($img, $x, $y, $rgbColor);
  548. }
  549. //上右
  550. $y_x = $w - $r; //圆心X坐标
  551. $y_y = $r; //圆心Y坐标
  552. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  553. imagesetpixel($img, $x, $y, $rgbColor);
  554. }
  555. //下左
  556. $y_x = $r; //圆心X坐标
  557. $y_y = $h - $r; //圆心Y坐标
  558. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  559. imagesetpixel($img, $x, $y, $rgbColor);
  560. }
  561. //下右
  562. $y_x = $w - $r; //圆心X坐标
  563. $y_y = $h - $r; //圆心Y坐标
  564. if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
  565. imagesetpixel($img, $x, $y, $rgbColor);
  566. }
  567. }
  568. }
  569. }
  570. return $img;
  571. }
  572. public function get_user_avatar($url, $member_id,$color=1)
  573. {
  574. //wepro_qrcode
  575. $header = array(
  576. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  577. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  578. 'Accept-Encoding: gzip, deflate',);
  579. $curl = curl_init();
  580. curl_setopt($curl, CURLOPT_URL, $url);
  581. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  582. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  583. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // false for https
  584. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  585. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  586. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  587. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
  588. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
  589. $data = curl_exec($curl);
  590. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  591. curl_close($curl);
  592. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  593. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  594. }
  595. $img_content=$imgBase64Code;//图片内容
  596. //echo $img_content;exit;
  597. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  598. {
  599. $type = $result[2];//得到图片类型png?jpg?gif?
  600. $image_dir = ROOT_PATH.'Uploads/image/';
  601. $send_path = 'goods/'.date('Y-m-d').'/';
  602. $image_dir .= $send_path;
  603. RecursiveMkdir($image_dir);
  604. $new_file = md5($url).".{$type}";
  605. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  606. if ($res)
  607. {
  608. list($src_w, $src_h) = getimagesize($image_dir.$new_file);
  609. if($color != 1)
  610. {
  611. $thumb_image_name = resize($send_path.$new_file, 32,32);
  612. $new_file = $thumb_image_name;
  613. //$new_file = str_replace($send_path,'',$new_file);
  614. $imgg = $this->radius_img(ROOT_PATH.$new_file, 32/2,$color);
  615. }else{
  616. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,$color);
  617. $new_file = 'Uploads/image/'.$send_path.$new_file;
  618. }
  619. if($type == 'jpeg' || $type == 'jpg')
  620. {
  621. imagejpeg($imgg, ROOT_PATH.$new_file);
  622. }else{
  623. imagepng($imgg, ROOT_PATH.$new_file);
  624. }
  625. //imagepng($imgg);
  626. //imagegif($imgg)
  627. imagedestroy($imgg);
  628. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('wepro_qrcode' => $new_file) );
  629. return $new_file;
  630. }else{
  631. return '';
  632. }
  633. }
  634. }
  635. /**
  636. * 商品详情海报头像
  637. * @param [type] $url [description]
  638. * @param [type] $member_id [description]
  639. * @param integer $color [description]
  640. * @return [type] [description]
  641. */
  642. public function get_goods_user_avatar($url, $member_id, $color=1)
  643. {
  644. $header = array(
  645. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  646. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  647. 'Accept-Encoding: gzip, deflate',
  648. );
  649. $curl = curl_init();
  650. curl_setopt($curl, CURLOPT_URL, $url);
  651. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  652. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  653. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // false for https
  654. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  655. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  656. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  657. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
  658. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
  659. $data = curl_exec($curl);
  660. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  661. curl_close($curl);
  662. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  663. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  664. }
  665. $img_content=$imgBase64Code;//图片内容
  666. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  667. {
  668. $type = $result[2];//得到图片类型png?jpg?gif?
  669. $image_dir = ROOT_PATH.'Uploads/image/';
  670. $send_path = 'goods/'.date('Y-m-d').'/';
  671. $image_dir .= $send_path;
  672. RecursiveMkdir($image_dir);
  673. $new_file = md5($url).".{$type}";
  674. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  675. if ($res)
  676. {
  677. list($src_w, $src_h) = getimagesize($image_dir.$new_file);
  678. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,$color);
  679. $new_file = 'Uploads/image/'.$send_path.$new_file;
  680. if($type == 'jpeg' || $type == 'jpg')
  681. {
  682. imagejpeg($imgg, ROOT_PATH.$new_file);
  683. }else{
  684. imagepng($imgg, ROOT_PATH.$new_file);
  685. }
  686. imagedestroy($imgg);
  687. return $new_file;
  688. }else{
  689. return '';
  690. }
  691. }
  692. }
  693. public function get_commission_user_avatar($url, $member_id,$color=1)
  694. {
  695. global $_W;
  696. global $_GPC;
  697. //wepro_qrcode
  698. $header = array(
  699. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  700. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  701. 'Accept-Encoding: gzip, deflate',);
  702. $curl = curl_init();
  703. curl_setopt($curl, CURLOPT_URL, $url);
  704. if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
  705. curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  706. }
  707. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  708. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  709. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // false for https
  710. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  711. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  712. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  713. $data = curl_exec($curl);
  714. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  715. curl_close($curl);
  716. if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
  717. $imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
  718. }
  719. $img_content=$imgBase64Code;//图片内容
  720. //echo $img_content;exit;
  721. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
  722. {
  723. $type = $result[2];//得到图片类型png?jpg?gif?
  724. $image_dir = ROOT_PATH.'Uploads/image/';
  725. $send_path = 'goods/'.date('Y-m-d').'/';
  726. $image_dir .= $send_path;
  727. RecursiveMkdir($image_dir);
  728. $new_file = md5($url).".{$type}";
  729. $res = file_put_contents($image_dir.$new_file, base64_decode(str_replace($result[1], '', $img_content)));
  730. if ($res)
  731. {
  732. list($src_w, $src_h) = getimagesize($image_dir.$new_file);
  733. if($color == 5)
  734. {
  735. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,5);
  736. }
  737. else if($color != 1)
  738. {
  739. $thumb_image_name = resize($send_path.$new_file, 100,100);
  740. $new_file = $thumb_image_name;
  741. $new_file = str_replace($send_path,'',$new_file);
  742. $imgg = $this->radius_img($image_dir.$new_file, 100/2,$color);
  743. }else{
  744. $imgg = $this->radius_img($image_dir.$new_file, $src_w/2,$color);
  745. }
  746. if($type == 'jpeg' || $type == 'jpg')
  747. {
  748. imagejpeg($imgg, $image_dir.$new_file);
  749. }else{
  750. imagepng($imgg, $image_dir.$new_file);
  751. }
  752. imagedestroy($imgg);
  753. return $send_path.$new_file;
  754. }else{
  755. return '';
  756. }
  757. }
  758. }
  759. public function _get_compare_qrcode_bgimg($bg_img, $qrcode_img,$avatar_image,$username, $s_x = '520',$s_y = '900')
  760. {
  761. //$image_dir = ROOT_PATH.'Uploads/image/';
  762. $send_path = "Uploads/image/".date('Y-m-d')."/";
  763. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  764. RecursiveMkdir($image_dir);
  765. $thumb_image_name = resize($qrcode_img, 230,230);
  766. $thumb_qrcode_img = ROOT_PATH.$thumb_image_name;
  767. $thumb_avatar_img = ROOT_PATH.$avatar_image;
  768. $bg_img = ROOT_PATH.$bg_img;
  769. $dst = imagecreatefromjpeg ($bg_img);
  770. $src = imagecreatefromstring(file_get_contents($thumb_qrcode_img));
  771. $src_avatar = imagecreatefromstring(file_get_contents($thumb_avatar_img));
  772. if (imageistruecolor($src))
  773. imagetruecolortopalette($src, false, 65535);
  774. list($src_w, $src_h) = getimagesize($thumb_qrcode_img);
  775. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  776. imagecopymerge($dst, $src, 442, 1020, 0, 0, $src_w, $src_h, 100);
  777. list($src_w, $src_h) = getimagesize($thumb_avatar_img);
  778. //list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  779. imagecopymerge($dst, $src_avatar, 65, 45, 0, 0, $src_w, $src_h, 100);
  780. $last_img = $image_dir;
  781. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  782. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  783. $gray1 = imagecolorallocate($dst, 23, 23, 23); //#333 51, 51, 51
  784. $white = imagecolorallocate($dst, 255, 255, 255); //#333 51, 51, 51
  785. $yellow = imagecolorallocate($dst, 255, 255, 0); //#333 51, 51, 51
  786. imagefttext($dst, 20, 0, 470, 1297, $gray1, $pingfang_med_path, '长按识别小程序');
  787. // $username = "试试我可以有多长,好长好长好长好长好长好长";
  788. $username = mb_substr($username,0,12,'utf-8');
  789. imagefttext($dst, 30, 0, 212, 94, $white, $pingfang_med_path, '@'.$username);
  790. $desc_txt = "分享了一个好东西";
  791. imagefttext($dst, 26, 0, 212, 148, $yellow, $pingfang_med_path, $desc_txt);
  792. $last_img_name = "last_qrcode".md5( time().$bg_img.$qrcode_img).'';
  793. switch ($dst_type) {
  794. case 1://GIF
  795. $last_img_name .= '.gif';
  796. header('Content-Type: image/gif');
  797. imagegif($dst, $last_img.$last_img_name);
  798. break;
  799. case 2://JPG
  800. $last_img_name .= '.jpg';
  801. //header('Content-Type: image/jpeg');
  802. imagejpeg($dst, $last_img.$last_img_name);
  803. break;
  804. case 3://PNG
  805. $last_img_name .= '.png';
  806. header('Content-Type: image/png');
  807. imagepng($dst, $last_img.$last_img_name);
  808. break;
  809. default:
  810. break;
  811. }
  812. imagedestroy($dst);
  813. imagedestroy($src);
  814. //imagedestroy($goods_src);
  815. //imagedestroy($avatar_src);
  816. //return_file_path
  817. $result = array('full_path' => $send_path.$last_img_name,'need_path' => $send_path.$last_img_name);
  818. return $result;
  819. }
  820. public function _get_commmon_wxqrcode($path='',$scene)
  821. {
  822. /**
  823. $jssdk = new \Lib\Weixin\Jssdk( C('weprogram_appid'), C('weprogram_appscret') );
  824. $weqrcode = $jssdk->getAllWeQrcode('pages/order/hexiao_bind',SELLERUID.'_0' );
  825. //保存图片
  826. $image_dir = ROOT_PATH.'Uploads/image/goods';
  827. $image_dir .= '/'.date('Y-m-d').'/';
  828. $file_path = C('SITE_URL').'Uploads/image/goods/'.date('Y-m-d').'/';
  829. $kufile_path = $dir.'/'.date('Y-m-d').'/';
  830. RecursiveMkdir($image_dir);
  831. $file_name = md5('qrcode_'.$pick_order_info['pick_sn'].time()).'.png';
  832. file_put_contents($image_dir.$file_name, $weqrcode);
  833. **/
  834. $weixin_config = array();
  835. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  836. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  837. $qrcode_rgb = D('Home/Front')->get_config_by_name('qrcode_rgb');
  838. if( !empty($qrcode_rgb) )
  839. {
  840. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  841. }
  842. //qrcode
  843. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  844. //$weqrcode = $jssdk->getAllWeQrcode($path,$scene);
  845. $weqrcode = $jssdk->getAllWeQrcode($path,$scene ,false,$qrcode_arr);
  846. $res_ck = json_decode($weqrcode, true);
  847. if( !empty($res_ck) && isset($res_ck['errcode']) )
  848. {
  849. return '';
  850. }else {
  851. //保存图片
  852. $image_dir = ROOT_PATH.'Uploads/image/';
  853. $image_dir .= 'goods'.date('Y-m-d').'/';
  854. RecursiveMkdir($image_dir);
  855. $file_name = md5('qrcode_'.$weqrcode.time()).'.png';
  856. file_put_contents($image_dir.$file_name, $weqrcode);
  857. //.......
  858. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  859. if( $attachment_type_arr['value'] == 1 )
  860. {
  861. save_image_to_qiniu($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  862. }else if( $attachment_type_arr['value'] == 2 ){
  863. save_image_to_alioss($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  864. }else if( $attachment_type_arr['value'] == 3 ){
  865. $res = save_image_to_txyun($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  866. }
  867. return 'goods'.date('Y-m-d').'/'.$file_name;
  868. }
  869. }
  870. function hex2rgb( $colour ) {
  871. if ( $colour[0] == '#' ) {
  872. $colour = substr( $colour, 1 );
  873. }
  874. if ( strlen( $colour ) == 6 ) {
  875. list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
  876. } elseif ( strlen( $colour ) == 3 ) {
  877. list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
  878. } else {
  879. return false;
  880. }
  881. $r = hexdec( $r );
  882. $g = hexdec( $g );
  883. $b = hexdec( $b );
  884. return array( 'r' => $r, 'g' => $g, 'b' => $b );
  885. }
  886. public function _get_index_wxqrcode($member_id,$community_id,$suffix="png")
  887. {
  888. $weixin_config = array();
  889. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  890. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  891. $qrcode_rgb = D('Home/Front')->get_config_by_name('qrcode_rgb');
  892. $qrcode_arr = array();
  893. if( !empty($qrcode_rgb) )
  894. {
  895. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  896. }
  897. //qrcode
  898. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  899. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/pages/index/index',$community_id .'_'. $member_id,$suffix=="png",$qrcode_arr);
  900. //line_color
  901. //保存图片
  902. $send_path = "Uploads/image/".date('Y-m-d')."/";
  903. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  904. RecursiveMkdir($image_dir);
  905. $file_name = md5('qrcode_'.$goods_id.'_'.$member_id.time()).'.'.$suffix;
  906. //qrcode
  907. file_put_contents($image_dir.$file_name, $weqrcode);
  908. return $send_path.$file_name;
  909. }
  910. public function _get_goods_user_wxqrcode($goods_id,$member_id,$community_id)
  911. {
  912. $weixin_config = array();
  913. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  914. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  915. //qrcode
  916. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  917. $qrcode_rgb = D('Home/Front')->get_config_by_name('qrcode_rgb');
  918. if( !empty($qrcode_rgb) )
  919. {
  920. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  921. }
  922. //lionfish_comshop/pages/goods/goodsDetail
  923. if($goods_id == 0)
  924. {
  925. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/pages/index/index',$goods_id.'_'.$member_id.'_'.$community_id ,false,$qrcode_arr);
  926. }else{
  927. $gd_info = M('lionfish_comshop_goods')->field('type')->where( array('id'=>$goods_id) )->find();
  928. if( $gd_info['type'] == 'pin' )
  929. {
  930. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/moduleA/pin/goodsDetail',$goods_id.'_'.$member_id.'_'.$community_id ,false,$qrcode_arr);
  931. }else{
  932. $weqrcode = $jssdk->getAllWeQrcode('lionfish_comshop/pages/goods/goodsDetail',$goods_id.'_'.$member_id.'_'.$community_id ,false,$qrcode_arr);
  933. }
  934. }
  935. //line_color
  936. //var_dump($weqrcode);die();
  937. //保存图片
  938. $send_path = "Uploads/image/goods/".date('Y-m-d')."/";
  939. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  940. $send_path_re = "goods/".date('Y-m-d')."/";
  941. RecursiveMkdir($image_dir);
  942. $file_name = md5('qrcode_'.$goods_id.'_'.$member_id.time()).'.jpg';
  943. //qrcode
  944. file_put_contents($image_dir.$file_name, $weqrcode);
  945. return $send_path_re.$file_name;
  946. }
  947. public function _get_compare_zan_img($goods_img,$goods_title,$goods_price, $seller_count,$quantity,$type="normal")
  948. {
  949. $send_path = "Uploads/image/goods/".date('Y-m-d')."/";
  950. $image_dir = ROOT_PATH.$send_path; //上传文件路径
  951. $send_path_re = "goods/".date('Y-m-d')."/";
  952. RecursiveMkdir($image_dir);
  953. //
  954. $bg_img = ROOT_PATH."/static/images/bg2.jpg";
  955. $haibao_gooods_bg2 = D('Home/Front')->get_config_by_name('haibao_gooods_bg2');
  956. if( isset($haibao_gooods_bg2) && !empty($haibao_gooods_bg2) )
  957. {
  958. $bg_img_path = ROOT_PATH."/Uploads/image/".$haibao_gooods_bg2;
  959. if( file_exists($bg_img_path) )
  960. {
  961. $bg_img = $bg_img_path;
  962. }
  963. }
  964. $thumb_goods_name = "thumb_img".md5($goods_img).'.png';
  965. $thumb_goods_img = resize($goods_img,700,700);
  966. $image_dir = ROOT_PATH.$send_path;
  967. $return_file_path = $send_path;
  968. //$image_dir.$thumb_avatar_name
  969. //商品图片 25 215
  970. //文字:65 955
  971. //长按二维码领取: 517 640
  972. //商品文字: 24 710
  973. //快和我一起领取吧: 24 817
  974. //市场价,单价 24 895
  975. //var_dump($thumb_goods_img);die();
  976. //$dst = imagecreatefromstring(file_get_contents($bg_img));
  977. $dst = imagecreatefromjpeg ($bg_img);
  978. $goods_src = imagecreatefromstring(file_get_contents(ROOT_PATH.$thumb_goods_img));
  979. if (imageistruecolor($goods_src))
  980. imagetruecolortopalette($goods_src, false, 65535);
  981. list($goods_src_w, $goods_src_h) = getimagesize(ROOT_PATH.$thumb_goods_img);
  982. list($dst_w, $dst_h, $dst_type) = getimagesize($bg_img);
  983. imagecopymerge($dst, $goods_src, 25, 215, 0, 0, $goods_src_w, $goods_src_h, 100);
  984. //imagecopymerge($dst, $avatar_src, 24, 615, 0, 0, $avatar_w, $avatar_h, 100);
  985. //IA_ROOT."/addons/lionfish_comshop/static/fonts/simhei.ttf"
  986. //$ttf_path = ROOT_PATH."Common/js/simhei.ttf";
  987. $ttf_path = ROOT_PATH."/static/fonts/simhei.ttf";
  988. $msyh_path = ROOT_PATH."/static/fonts/msyh.ttf";
  989. $pingfang_path = ROOT_PATH."/static/fonts/PingFang_Bold.ttf";
  990. $pingfang_med_path = ROOT_PATH."/static/fonts/PingFang_Medium.ttf";
  991. //打上文字
  992. $black = imagecolorallocate($dst, 20,20,20);//黑色
  993. $red = imagecolorallocate($dst, 237, 48, 43); //红色 201 55 49
  994. $huise = imagecolorallocate($dst, 159, 159, 159); //灰色 159 159 159
  995. $fense = imagecolorallocate($dst, 248, 136, 161); //粉色 248 136 161
  996. $gray1 = imagecolorallocate($dst, 51, 51, 51); //#333 51, 51, 51
  997. $gray2 = imagecolorallocate($dst, 102, 102, 6); //#666 102, 102, 6
  998. $gray3 = imagecolorallocate($dst, 153, 153, 153); //#999 153, 153, 153
  999. $chengse = imagecolorallocate($dst, 252, 74, 74); //#999
  1000. //ffb7d7 248 136 161
  1001. // $goods_title = "我免费领取了【大白兔奶糖果零食铁盒装114g】的所得税的色舞认太热太热太热";
  1002. $goods_title = $goods_title;
  1003. $need_goods_title = mb_substr($goods_title,0,18,'utf-8')."\r\n";
  1004. $need_goods_title .= mb_substr($goods_title,18,9,'utf-8');
  1005. //.'...'mb_strlen(
  1006. if( mb_strlen($goods_title,'utf-8') > 28)
  1007. {
  1008. $need_goods_title .= '...';
  1009. }
  1010. //imagefttext($dst, 25, 0, 120, 660, $black, $ttf_path, $username);
  1011. //imagefttext($dst, 15, 0, 518, 920, $huise, $ttf_path, '长按二维码领取'); 65 955
  1012. imagefttext($dst, 26, 0, 64, 987, $gray1, $pingfang_med_path, $need_goods_title);
  1013. // imagefttext($dst, 15, 0, 25, 1040, $fense, $ttf_path, "限时爆款价");
  1014. if($type=='integral') {
  1015. imagefttext($dst, 22, 0, 64, 1165, $chengse, $pingfang_path, "团购价:");
  1016. imagefttext($dst, 32, 0, 178, 1168, $chengse, $pingfang_path, $goods_price['price'].'积分');
  1017. $size_1 = sprintf('%.2f',$goods_price['market_price']);
  1018. imagefttext($dst, 18, 0, 64, 1115, $gray3, $pingfang_med_path, "原价: ¥".$size_1 );
  1019. } else {
  1020. imagefttext($dst, 22, 0, 64, 1165, $chengse, $pingfang_path, "团购价:");
  1021. imagefttext($dst, 32, 0, 178, 1168, $chengse, $pingfang_path, '¥'.$goods_price['price']);
  1022. $size_1 = sprintf('%.2f',$goods_price['market_price']);
  1023. imagefttext($dst, 18, 0, 64, 1115, $gray3, $pingfang_med_path, "原价:¥".$size_1 );
  1024. }
  1025. $size_12 = strlen($size_1);
  1026. $pos = 145 + intval(15 * ($size_12-1)+5);
  1027. imageline($dst, 122, 1105, $pos, 1105, $gray3); //画线
  1028. //imageline($dst, 122, 1105, $pos, 1105, $gray3); //画线
  1029. imagefttext($dst, 16, 0, 64, 1270, $chengse, $pingfang_med_path, "已售{$seller_count}件");
  1030. imagefttext($dst, 16, 0, 212, 1270, $chengse, $pingfang_med_path, "仅剩{$quantity}件");
  1031. //$seller_count,$quantity 已售10件
  1032. $last_img = $image_dir;
  1033. $last_img_name = "last_avatar".md5( time().$need_goods_title.$username).'';
  1034. switch ($dst_type) {
  1035. case 1://GIF
  1036. $last_img_name .= '.gif';
  1037. header('Content-Type: image/gif');
  1038. imagegif($dst, $last_img.$last_img_name);
  1039. break;
  1040. case 2://JPG
  1041. $last_img_name .= '.jpg';
  1042. //header('Content-Type: image/jpeg');
  1043. imagejpeg($dst, $last_img.$last_img_name);
  1044. break;
  1045. case 3://PNG
  1046. $last_img_name .= '.png';
  1047. header('Content-Type: image/png');
  1048. imagepng($dst, $last_img.$last_img_name);
  1049. break;
  1050. default:
  1051. break;
  1052. }
  1053. imagedestroy($dst);
  1054. imagedestroy($goods_src);
  1055. //imagedestroy($avatar_src); imageistruecolor
  1056. //return_file_path
  1057. $result = array('full_path' => $send_path.$last_img_name,'need_path' => $send_path_re.$last_img_name);
  1058. return $result;
  1059. }
  1060. /**
  1061. 关注取消商品收藏
  1062. 删除返回1
  1063. **/
  1064. public function user_fav_goods_toggle($goods_id, $member_id)
  1065. {
  1066. $res = $this->check_goods_fav($goods_id, $member_id);
  1067. if($res)
  1068. {
  1069. //删除
  1070. M('lionfish_comshop_user_favgoods')->where( array('goods_id' => $goods_id,'member_id' => $member_id) )->delete();
  1071. return 1;
  1072. } else {
  1073. //添加
  1074. $data = array();
  1075. $data['member_id'] = $member_id;
  1076. $data['goods_id'] = $goods_id;
  1077. $data['add_time'] = time();
  1078. M('lionfish_comshop_user_favgoods')->add($data);
  1079. return 2;
  1080. }
  1081. }
  1082. public function check_goods_fav($goods_id, $member_id)
  1083. {
  1084. $user_favgoods = M('lionfish_comshop_user_favgoods')->where( array('member_id' => $member_id, 'goods_id' => $goods_id) )->find();
  1085. if(!empty($user_favgoods))
  1086. {
  1087. return true;
  1088. } else {
  1089. return false;
  1090. }
  1091. }
  1092. /**
  1093. 获取商品的分佣金额
  1094. **/
  1095. public function get_goods_commission_info($goods_id,$member_id, $is_parse = false)
  1096. {
  1097. $result = array();
  1098. //1 比例,2固定金额
  1099. $result['commiss_one'] = array('money' => 0,'fen' => 0, 'type' => 1);
  1100. $result['commiss_two'] = array('money' => 0,'fen' => 0, 'type' => 1);
  1101. $result['commiss_three'] = array('money' => 0,'fen' => 0, 'type' => 1);
  1102. $goods_commiss = M('lionfish_comshop_good_commiss')->where( array('goods_id' => $goods_id ) )->find();
  1103. $gd_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $goods_id ) )->find();
  1104. if($goods_commiss['nocommission'] == 1 || $gd_info['type'] == 'integral' )
  1105. {
  1106. return $result;
  1107. }else{
  1108. //hascommission
  1109. if($goods_commiss['hascommission'] == 1 || $is_parse)
  1110. {
  1111. //自定义商品分佣
  1112. if( !empty($goods_commiss['commission1_rate']) && $goods_commiss['commission1_rate'] >0 )
  1113. {
  1114. $result['commiss_one'] = array('money' => 0,'fen' => $goods_commiss['commission1_rate'], 'type' => 1);
  1115. }else{
  1116. $result['commiss_one'] = array('money' => $goods_commiss['commission1_pay'],'fen' => 0, 'type' => 2);
  1117. }
  1118. if( !empty($goods_commiss['commission2_rate']) && $goods_commiss['commission2_rate'] >0 )
  1119. {
  1120. $result['commiss_two'] = array('money' => 0,'fen' => $goods_commiss['commission2_rate'], 'type' => 1);
  1121. }else{
  1122. $result['commiss_two'] = array('money' => $goods_commiss['commission2_pay'],'fen' => 0, 'type' => 2);
  1123. }
  1124. if( !empty($goods_commiss['commission3_rate']) && $goods_commiss['commission3_rate'] >0 )
  1125. {
  1126. $result['commiss_three'] = array('money' => 0,'fen' => $goods_commiss['commission3_rate'], 'type' => 1);
  1127. }else{
  1128. $result['commiss_three'] = array('money' => $goods_commiss['commission3_pay'],'fen' => 0, 'type' => 2);
  1129. }
  1130. $parent_info = D('Home/Commission')->get_member_parent_list($member_id);
  1131. $result['parent_info'] = $parent_info;
  1132. }else{
  1133. //是否开启分销内购 commiss_selfbuy
  1134. $commiss_level_info = D('Home/Commission')->get_commission_level();
  1135. $commiss_selfbuy = D('Home/Front')->get_config_by_name('commiss_selfbuy');
  1136. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1137. $parent_info = D('Home/Commission')->get_member_parent_list($member_id);
  1138. if($commiss_selfbuy == 1)
  1139. {
  1140. //开启分销内购
  1141. if( $member_info['comsiss_state'] == 1 && $member_info['comsiss_flag'] == 1 )
  1142. {
  1143. $parent_info['self_go'] = array('member_id' =>$member_id, 'level_id' => $member_info['commission_level_id']);
  1144. }
  1145. }
  1146. //开始分析分佣比例
  1147. if( isset($parent_info['self_go']) && !empty($parent_info['self_go']['member_id']) )
  1148. {
  1149. $result['commiss_one'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['self_go']['level_id'] ]['commission'], 'type' => 1);
  1150. $result['commiss_two'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['one']['level_id']]['commission2'], 'type' => 1);
  1151. $result['commiss_three'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['two']['level_id']]['commission3'], 'type' => 1);
  1152. }else{
  1153. $result['commiss_one'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['one']['level_id']]['commission'], 'type' => 1);
  1154. $result['commiss_two'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['two']['level_id']]['commission2'], 'type' => 1);
  1155. $result['commiss_three'] = array('money' => 0,'fen' => $commiss_level_info[$parent_info['three']['level_id']]['commission3'], 'type' => 1);
  1156. }
  1157. }
  1158. return $result;
  1159. }
  1160. }
  1161. /**
  1162. 获取商品列表
  1163. **/
  1164. public function get_goods_list($fields='*', $where='1=1',$order='index_sort desc ,seller_count desc,id asc',$offset=0,$perpage=10)
  1165. {
  1166. $list = M('lionfish_comshop_goods')->field($fields)->where($where)->order($order)->limit($offset,$perpage)->select();
  1167. return $list;
  1168. }
  1169. /**
  1170. 获取商品图片
  1171. **/
  1172. public function get_goods_images($goods_id, $limit =1)
  1173. {
  1174. if($limit == 1)
  1175. {
  1176. $image_info = M('lionfish_comshop_goods_images')->where( array('goods_id' => $goods_id) )->order('id asc')->find();
  1177. return $image_info;
  1178. }else{
  1179. $image_list = M('lionfish_comshop_goods_images')->where( array('goods_id' => $goods_id) )->order('id asc')->select();
  1180. return $image_list;
  1181. }
  1182. }
  1183. /**
  1184. 商品喜欢的数量
  1185. **/
  1186. public function fav_goods_count($goods_id)
  1187. {
  1188. $total = M('lionfish_comshop_user_favgoods')->where( array('goods_id' => $goods_id) )->count();
  1189. return $total;
  1190. }
  1191. /**
  1192. 会员喜欢商品状态
  1193. **/
  1194. public function fav_goods_state($goods_id, $member_id)
  1195. {
  1196. $fav_info = M('lionfish_comshop_user_favgoods')->where( array('goods_id' => $goods_id, 'member_id' => $member_id) )->find();
  1197. return $fav_info;
  1198. }
  1199. /**
  1200. 获取商品价格
  1201. **/
  1202. public function get_goods_price($goods_id,$member_id = 0)
  1203. {
  1204. $price_arr = array();
  1205. $goods_info = M('lionfish_comshop_goods')->field('is_take_vipcard,price as danprice,type,card_price,mead_money_num')->where( array('id' => $goods_id))->find();
  1206. if($goods_info['type'] =='pin')
  1207. {
  1208. $pin_goods_info = M('lionfish_comshop_good_pin')->field('pinprice,pin_count')->where( array('goods_id' => $goods_id ) )->find();
  1209. if(!empty($pin_goods_info))
  1210. {
  1211. $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']);
  1212. $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();
  1213. if( !empty($option_price_arr) )
  1214. {
  1215. $price_arr['danprice'] = $option_price_arr['dan_price'];
  1216. }
  1217. $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();
  1218. $max_option_pinprice_arr = M('lionfish_comshop_goods_option_item_value')->field('pinprice as pin_price')->where( array('goods_id' => $goods_id) )->order('pinprice desc')->find();
  1219. if( !empty($option_pinprice_arr) )
  1220. {
  1221. $price_arr['price'] = $option_pinprice_arr['pin_price'];
  1222. $price_arr['pin_price'] = $option_pinprice_arr['pin_price'];
  1223. }
  1224. if( $max_option_pinprice_arr['pin_price'] > $option_pinprice_arr['pin_price'])
  1225. {
  1226. $price_arr['max_pinprice'] = $max_option_pinprice_arr['pin_price'];
  1227. }
  1228. }
  1229. }else{
  1230. //获取最低价格
  1231. $option_price_arr = M('lionfish_comshop_goods_option_item_value')->field('id,marketprice as dan_price')
  1232. ->where( array('goods_id' => $goods_id) )->order('marketprice asc')->find();
  1233. $max_option_price_arr = M('lionfish_comshop_goods_option_item_value')
  1234. ->field('id,marketprice as dan_price')->where( array('goods_id' => $goods_id) )
  1235. ->order('marketprice desc')->find();
  1236. if( !empty($option_price_arr) && $option_price_arr['dan_price'] >= 0.01)
  1237. {
  1238. $price_arr = array('price' => $option_price_arr['dan_price'],'danprice' => $option_price_arr['dan_price']);
  1239. if( $max_option_price_arr['dan_price'] > $option_price_arr['dan_price'])
  1240. {
  1241. $price_arr['max_danprice'] = $max_option_price_arr['dan_price'];
  1242. }
  1243. }else{
  1244. $price_arr = array('price' => $goods_info['danprice'],'danprice' => $goods_info['danprice']);
  1245. }
  1246. $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();
  1247. if( !empty($option_cardprice_arr) && $option_cardprice_arr['card_price'] >= 0.01)
  1248. {
  1249. $price_arr['card_price'] = $option_cardprice_arr['card_price'];
  1250. }else{
  1251. $price_arr['card_price'] = $goods_info['card_price'];
  1252. }
  1253. }
  1254. //修改商品独立会员等级折扣设置 2020.05.11
  1255. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy,has_mb_level_buy,mb_level_buy_list')->where( array('goods_id' => $goods_id ) )->find();
  1256. $price_arr['is_mb_level_buy'] = 0;
  1257. //新增的会员折扣 begin
  1258. if($goods_info['type'] !='pin')
  1259. {
  1260. //商品独立会员等级折扣 begin
  1261. if($member_id > 0 && $goods_common['has_mb_level_buy'] == 1) {
  1262. $member_info = M('lionfish_comshop_member')->field('level_id')->where(array('member_id' => $member_id))->find();
  1263. if ($member_info['level_id'] > 0){
  1264. $mb_level_buy_list = unserialize($goods_common['mb_level_buy_list']);
  1265. $mb_level_discount_list = array();
  1266. foreach($mb_level_buy_list as $k=>$v){
  1267. $mb_level_discount_list[$v['level_id']] = $v['discount'];
  1268. }
  1269. if( $mb_level_discount_list[$member_info['level_id']]>0 && $mb_level_discount_list[$member_info['level_id']] <100 )
  1270. {
  1271. if(isset($mb_level_discount_list[$member_info['level_id']]) && !empty($mb_level_discount_list[$member_info['level_id']])){
  1272. $vipprice = round( ($price_arr['price'] * $mb_level_discount_list[$member_info['level_id']]) /100 ,2);
  1273. $vaipdanprice = round( ($price_arr['danprice'] * $mb_level_discount_list[$member_info['level_id']]) /100 ,2);
  1274. $price_arr['levelprice'] = sprintf('%.2f', $vipprice );
  1275. $price_arr['leveldanprice'] = sprintf('%.2f', $vaipdanprice );
  1276. }else{
  1277. $price_arr['levelprice'] = sprintf('%.2f', $price_arr['price'] );
  1278. $price_arr['leveldanprice'] = sprintf('%.2f', $price_arr['danprice'] );
  1279. }
  1280. $price_arr['is_mb_level_buy'] = 1;
  1281. }
  1282. }else{
  1283. $price_arr['levelprice'] = sprintf('%.2f', $price_arr['price'] );
  1284. $price_arr['leveldanprice'] = sprintf('%.2f', $price_arr['danprice'] );
  1285. $price_arr['is_mb_level_buy'] = 0;
  1286. }
  1287. //商品独立会员等级折扣 end
  1288. }else{
  1289. if($member_id >0 && $goods_common['is_mb_level_buy'] == 1 )
  1290. {
  1291. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
  1292. if( $member_info['level_id'] > 0)
  1293. {
  1294. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  1295. if( $member_level_info['discount']>0 && $member_level_info['discount']<100 )
  1296. {
  1297. $vipprice = round( ($price_arr['price'] * $member_level_info['discount']) /100 ,2);
  1298. $vaipdanprice = round( ($price_arr['danprice'] * $member_level_info['discount']) /100 ,2);
  1299. $price_arr['levelprice'] = sprintf('%.2f', $vipprice );
  1300. $price_arr['leveldanprice'] = sprintf('%.2f', $vaipdanprice );
  1301. $price_arr['is_mb_level_buy'] = 1;
  1302. }
  1303. }else{
  1304. $price_arr['levelprice'] = sprintf('%.2f', $price_arr['price'] );
  1305. $price_arr['leveldanprice'] = sprintf('%.2f', $price_arr['danprice'] );
  1306. $price_arr['is_mb_level_buy'] = 0;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. //1、开启未登录不显示价格,
  1312. $is_login_showprice = D('Home/Front')->get_config_by_name('is_login_showprice');
  1313. //-888给后台使用
  1314. if( !empty($is_login_showprice) && $is_login_showprice == 1 && $member_id != -888)
  1315. {
  1316. $member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
  1317. if( empty($member_id) || $member_id <= 0 || $member_info['is_apply_state'] == 0 )
  1318. {
  1319. /**
  1320. $price_arr = array(
  1321. 'price' =>$pin_goods_info['pinprice'],
  1322. 'danprice' =>$goods_info['danprice'],
  1323. 'pin_price' =>$pin_goods_info['pinprice'],
  1324. );
  1325. $price_arr['max_pinprice']
  1326. $price_arr['card_price']
  1327. $price_arr['levelprice'] = sprintf('%.2f', $vipprice );
  1328. $price_arr['leveldanprice'] = sprintf('%.2f', $vaipdanprice );
  1329. **/
  1330. if( isset($price_arr['price']) )
  1331. {
  1332. $price_arr['price'] = '--';
  1333. }
  1334. if( isset($price_arr['danprice']) )
  1335. {
  1336. $price_arr['danprice'] = '--';
  1337. }
  1338. if( isset($price_arr['pin_price']) )
  1339. {
  1340. $price_arr['pin_price'] = '--';
  1341. }
  1342. if( isset($price_arr['max_pinprice']) )
  1343. {
  1344. $price_arr['max_pinprice'] = '--';
  1345. }
  1346. if( isset($price_arr['card_price']) )
  1347. {
  1348. $price_arr['card_price'] = '--';
  1349. }
  1350. if( isset($price_arr['levelprice']) )
  1351. {
  1352. $price_arr['levelprice'] = '--';
  1353. }
  1354. if( isset($price_arr['leveldanprice']) )
  1355. {
  1356. $price_arr['leveldanprice'] = '--';
  1357. }
  1358. }
  1359. }else{
  1360. //mead
  1361. // foreach ($price_arr as $key => $value){
  1362. // if($key == 'is_mb_level_buy') continue;
  1363. //// $price_arr[$key] = meadMoney($value,$goods_info['mead_money_num']);
  1364. // }
  1365. }
  1366. return $price_arr;
  1367. }
  1368. public function get_goods_description($goods_id,$fields='*') {
  1369. $goods_info = M('goods_description')->field($fields)->where( array('goods_id' => $goods_id) )->find();
  1370. return $goods_info;
  1371. }
  1372. public function get_goods_options($goods_id,$member_id =0)
  1373. {
  1374. $result = array();
  1375. $goods_option_name = array();
  1376. $goods_option_data = array();
  1377. $goods_info = M('lionfish_comshop_goods')->field('goodsname,productprice')->where( array('id' => $goods_id ) )->find();
  1378. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy')->where( array('goods_id' => $goods_id ) )->find();
  1379. $goods_option_query = M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id) )->select();
  1380. $sku_goods_image = '';
  1381. $good_image = $this->get_goods_images($goods_id);
  1382. if( !empty($good_image) )
  1383. {
  1384. $sku_goods_image = tomedia($good_image['image']);
  1385. }
  1386. if( !empty($goods_option_query) )
  1387. {
  1388. $option_item_image = array();
  1389. foreach ($goods_option_query as $goods_option) {
  1390. $goods_option_value_data = array();
  1391. $goods_option_value_query = M('lionfish_comshop_goods_option_item')->where( array('goods_option_id' => $goods_option['id']) )->order('displayorder desc,id desc')->select();
  1392. foreach ($goods_option_value_query as $goods_option_value) {
  1393. $goods_option_value_data[] = array(
  1394. 'goods_option_value_id' => $goods_option_value['id'],
  1395. 'option_value_id' => $goods_option_value['id'],
  1396. 'name' =>$goods_option_value['title'],
  1397. 'image' =>isset($goods_option_value['thumb']) ? tomedia($goods_option_value['thumb']) : '',
  1398. );
  1399. if(!empty($goods_option_value['thumb']))
  1400. {
  1401. $option_item_image[$goods_option_value['id']] = tomedia($goods_option_value['thumb']);
  1402. }
  1403. }
  1404. $goods_option_name[] = $goods_option['title'];
  1405. $goods_option_data[] = array(
  1406. 'goods_option_id' => $goods_option['id'],
  1407. 'option_id' => $goods_option['id'],
  1408. 'name' => $goods_option['title'],
  1409. 'option_value' => $goods_option_value_data,
  1410. );
  1411. }
  1412. $result['list'] = $goods_option_data;
  1413. $result['name'] = $goods_option_name;
  1414. if($member_id >0)
  1415. {
  1416. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
  1417. if( $member_info['level_id'] > 0)
  1418. {
  1419. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  1420. }
  1421. }
  1422. $mult_item_list = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id) )->select();
  1423. $sku_mu_list = array();
  1424. foreach($mult_item_list as $val)
  1425. {
  1426. //goodsname,productprice
  1427. $val['levelprice'] = $val['marketprice'];
  1428. if($member_id >0 && $goods_common['is_mb_level_buy'] == 1)
  1429. {
  1430. if( $member_info['level_id'] > 0)
  1431. {
  1432. $val['levelprice'] = round( ($val['marketprice'] * $member_level_info['discount']) /100 ,2);
  1433. //$val['pinprice'] = round( ($val['pinprice'] * $member_level_info['discount']) /100 ,2);
  1434. }
  1435. }
  1436. $tmp_arr = array();
  1437. $tmp_arr['spec'] = $val['title'];
  1438. $tmp_arr['canBuyNum'] = $val['stock'];
  1439. $tmp_arr['spuName'] = $goods_info['goodsname'];
  1440. $tmp_arr['actPrice'] = explode('.', $val['marketprice']);
  1441. $tmp_arr['marketPrice'] = explode('.', $val['productprice']);
  1442. $tmp_arr['pinprice'] = explode('.', $val['pinprice']);
  1443. $tmp_arr['card_price'] = explode('.', $val['card_price']);
  1444. $tmp_arr['levelprice'] = explode('.', $val['levelprice']);
  1445. $tmp_arr['option_item_ids'] = $val['option_item_ids'];
  1446. $tmp_arr['stock'] = $val['stock'];
  1447. $ids_option = explode('_', $val['option_item_ids']);
  1448. $img = '';
  1449. foreach($ids_option as $vv)
  1450. {
  1451. if(isset($option_item_image[$vv]))
  1452. {
  1453. $img = $option_item_image[$vv];
  1454. break;
  1455. }
  1456. }
  1457. if( empty($img) )
  1458. {
  1459. $img = $sku_goods_image;
  1460. }
  1461. $tmp_arr['skuImage'] = $img;
  1462. $sku_mu_list[$val['option_item_ids']] = $tmp_arr;
  1463. }
  1464. $result['sku_mu_list'] = $sku_mu_list;
  1465. //array('spec' => 'xl','canBuyNum' => 100,'spuName' => 1, 'actPrice' => array(1,2), 'marketPrice' => array(2,3),'skuImage' => tomedia($good_image['image'])),
  1466. }
  1467. return $result;
  1468. }
  1469. /**
  1470. * 获取商品规格信息及购物车数量
  1471. * @param $goods_id
  1472. * @param int $member_id
  1473. * @return array
  1474. */
  1475. public function get_goods_options_carquantity($goods_id,$member_id =0,$head_id ,$token)
  1476. {
  1477. $result = array();
  1478. $goods_option_name = array();
  1479. $goods_option_data = array();
  1480. $goods_info = M('lionfish_comshop_goods')->field('goodsname,productprice,mead_money_num')->where( array('id' => $goods_id ) )->find();
  1481. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy')->where( array('goods_id' => $goods_id ) )->find();
  1482. $goods_option_query = M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id) )->select();
  1483. $sku_goods_image = '';
  1484. $good_image = $this->get_goods_images($goods_id);
  1485. if( !empty($good_image) )
  1486. {
  1487. $sku_goods_image = tomedia($good_image['image']);
  1488. }
  1489. if( !empty($goods_option_query) )
  1490. {
  1491. $option_item_image = array();
  1492. foreach ($goods_option_query as $goods_option) {
  1493. $goods_option_value_data = array();
  1494. $goods_option_value_query = M('lionfish_comshop_goods_option_item')->where( array('goods_option_id' => $goods_option['id']) )->order('displayorder desc,id desc')->select();
  1495. foreach ($goods_option_value_query as $goods_option_value) {
  1496. $goods_option_value_data[] = array(
  1497. 'goods_option_value_id' => $goods_option_value['id'],
  1498. 'option_value_id' => $goods_option_value['id'],
  1499. 'name' =>$goods_option_value['title'],
  1500. 'image' =>isset($goods_option_value['thumb']) ? tomedia($goods_option_value['thumb']) : '',
  1501. );
  1502. if(!empty($goods_option_value['thumb']))
  1503. {
  1504. $option_item_image[$goods_option_value['id']] = tomedia($goods_option_value['thumb']);
  1505. }
  1506. }
  1507. $goods_option_name[] = $goods_option['title'];
  1508. $goods_option_data[] = array(
  1509. 'goods_option_id' => $goods_option['id'],
  1510. 'option_id' => $goods_option['id'],
  1511. 'name' => $goods_option['title'],
  1512. 'option_value' => $goods_option_value_data,
  1513. );
  1514. }
  1515. $result['list'] = $goods_option_data;
  1516. $result['name'] = $goods_option_name;
  1517. if($member_id >0)
  1518. {
  1519. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
  1520. if( $member_info['level_id'] > 0)
  1521. {
  1522. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  1523. }
  1524. }
  1525. $mult_item_list = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id) )->select();
  1526. $is_login_showprice = D('Home/Front')->get_config_by_name('is_login_showprice');
  1527. $sku_mu_list = array();
  1528. foreach($mult_item_list as $val)
  1529. {
  1530. //goodsname,productprice
  1531. $val['levelprice'] = $val['marketprice'];
  1532. if($member_id >0 && $goods_common['is_mb_level_buy'] == 1)
  1533. {
  1534. if( $member_info['level_id'] > 0)
  1535. {
  1536. $val['levelprice'] = round( ($val['marketprice'] * $member_level_info['discount']) /100 ,2);
  1537. //$val['pinprice'] = round( ($val['pinprice'] * $member_level_info['discount']) /100 ,2);
  1538. }
  1539. }
  1540. //mead
  1541. $val['marketprice'] = meadMoney($val['marketprice'],$goods_info['mead_money_num']);
  1542. $val['productprice'] = meadMoney($val['productprice'],$goods_info['mead_money_num']);
  1543. $val['pinprice'] = meadMoney($val['pinprice'],$goods_info['mead_money_num']);
  1544. $val['card_price'] = meadMoney($val['card_price'],$goods_info['mead_money_num']);
  1545. $val['levelprice'] = meadMoney($val['levelprice'],$goods_info['mead_money_num']);
  1546. $tmp_arr = array();
  1547. $tmp_arr['spec'] = $val['title'];
  1548. $tmp_arr['canBuyNum'] = $val['stock'];
  1549. $tmp_arr['spuName'] = $goods_info['goodsname'];
  1550. $tmp_arr['actPrice'] = explode('.', $val['marketprice']);
  1551. $tmp_arr['marketPrice'] = explode('.', $val['productprice']);
  1552. $tmp_arr['pinprice'] = explode('.', $val['pinprice']);
  1553. $tmp_arr['card_price'] = explode('.', $val['card_price']);
  1554. $tmp_arr['levelprice'] = explode('.', $val['levelprice']);
  1555. //1、开启未登录不显示价格,
  1556. if( !empty($is_login_showprice) && $is_login_showprice == 1 )
  1557. {
  1558. $member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
  1559. if( empty($member_id) || $member_id <= 0 || $member_info['is_apply_state'] == 0 )
  1560. {
  1561. $tmp_arr['actPrice'] = '--';
  1562. $tmp_arr['pinprice'] = '--';
  1563. $tmp_arr['card_price'] = '--';
  1564. $tmp_arr['levelprice'] = '--';
  1565. }
  1566. }
  1567. $tmp_arr['option_item_ids'] = $val['option_item_ids'];
  1568. $tmp_arr['stock'] = $val['stock'];
  1569. $ids_option = explode('_', $val['option_item_ids']);
  1570. $sku_carquantity = D('Home/Car')->get_wecart_goods($goods_id,$val['option_item_ids'],$head_id ,$token);
  1571. $tmp_arr['car_quantity'] = !empty($sku_carquantity) ? $sku_carquantity : 0;
  1572. $img = '';
  1573. foreach($ids_option as $vv)
  1574. {
  1575. if(isset($option_item_image[$vv]))
  1576. {
  1577. $img = $option_item_image[$vv];
  1578. break;
  1579. }
  1580. }
  1581. if( empty($img) )
  1582. {
  1583. $img = $sku_goods_image;
  1584. }
  1585. $tmp_arr['skuImage'] = $img;
  1586. $sku_mu_list[$val['option_item_ids']] = $tmp_arr;
  1587. }
  1588. $result['sku_mu_list'] = $sku_mu_list;
  1589. //array('spec' => 'xl','canBuyNum' => 100,'spuName' => 1, 'actPrice' => array(1,2), 'marketPrice' => array(2,3),'skuImage' => tomedia($good_image['image'])),
  1590. }
  1591. return $result;
  1592. }
  1593. /**
  1594. 判断规格是否失效
  1595. **/
  1596. public function get_goods_option_can_buy( $goods_id, $sku_str )
  1597. {
  1598. if( empty($sku_str) )
  1599. {
  1600. return 1;
  1601. }else{
  1602. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' =>$sku_str,'goods_id' => $goods_id ) )->find();
  1603. if( empty($goods_option_mult_value) )
  1604. {
  1605. return 0;
  1606. }else{
  1607. return 1;
  1608. }
  1609. }
  1610. }
  1611. public function get_goods_time_can_buy($goods_id)
  1612. {
  1613. $goods_info = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
  1614. if( $goods_info['total'] <= 0 || $goods_info['grounding'] != 1)
  1615. {
  1616. return 0;
  1617. }
  1618. $goods_info = M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->find();
  1619. $now_time = time();
  1620. if( $now_time<$goods_info['begin_time'] || $now_time > $goods_info['end_time'])
  1621. {
  1622. return 0;
  1623. }else{
  1624. return 1;
  1625. }
  1626. }
  1627. /**
  1628. 获取商品数量
  1629. **/
  1630. public function get_goods_count($where = '',$uniacid = 0)
  1631. {
  1632. $total = M('lionfish_comshop_goods')->where("1 ".$where)->count();
  1633. return $total;
  1634. }
  1635. /**
  1636. 给商品扣除库存
  1637. **/
  1638. /**
  1639. 扣除/增加商品多规格库存
  1640. 1扣除, 2 增加
  1641. **/
  1642. public function del_goods_mult_option_quantity($order_id,$option,$goods_id,$quantity,$type='1')
  1643. {
  1644. $tp_goods = M('lionfish_comshop_goods')->field('total as quantity')->where( array('id' => $goods_id) )->find();
  1645. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id, 'goods_id' => $goods_id ) )->find();
  1646. $option_list = M('lionfish_comshop_order_option')->where( array('order_id' => $order_id,'order_goods_id' => $goods_id) )->find();
  1647. if($type == 1)
  1648. {
  1649. $quantity_order_data = array();
  1650. $quantity_order_data['order_id'] = $order_id;
  1651. $quantity_order_data['goods_id'] = $goods_id;
  1652. $quantity_order_data['rela_goodsoption_value_id'] = $option;
  1653. $quantity_order_data['quantity'] = $quantity;
  1654. $quantity_order_data['type'] = 0;
  1655. $quantity_order_data['last_quantity'] = $tp_goods['quantity'];
  1656. $quantity_order_data['addtime'] = time();
  1657. $quantity_order_data['adddate'] = date('Y-m-d H:i:s');
  1658. M('lionfish_comshop_order_quantity_order')->add($quantity_order_data);
  1659. //扣除库存
  1660. $up_total_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET total = (total - " . (int)$quantity . ") where id={$goods_id} ";
  1661. M()->execute($up_total_sql);
  1662. //销量增加
  1663. $up_seller_count_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET seller_count = (seller_count + " . (int)$quantity . ") WHERE id = {$goods_id}";
  1664. M()->execute($up_seller_count_sql);
  1665. //释放出reids占位,还有取消订单也要释放出redis占位---begin
  1666. $order_info = M('lionfish_comshop_order')->field('member_id')->where( array('order_id' => $order_id) )->find();
  1667. $redis_has_add_list = array();
  1668. $redis_has_add_list[] = array('member_id' => $order_info['member_id'], 'goods_id' => $goods_id, 'sku_str' => $option );
  1669. //D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  1670. //D('Seller/Redisorder')->cancle_goods_buy_user($redis_has_add_list);
  1671. //--------end
  1672. } else if($type == 2){
  1673. $quantity_order_data = array();
  1674. $quantity_order_data['order_id'] = $order_id;
  1675. $quantity_order_data['goods_id'] = $goods_id;
  1676. $quantity_order_data['rela_goodsoption_value_id'] = $option;
  1677. $quantity_order_data['quantity'] = $quantity;
  1678. $quantity_order_data['type'] = 1;
  1679. $quantity_order_data['last_quantity'] = $tp_goods['quantity'];
  1680. $quantity_order_data['addtime'] = time();
  1681. $quantity_order_data['adddate'] = date('Y-m-d H:i:s');
  1682. M('lionfish_comshop_order_quantity_order')->add($quantity_order_data);
  1683. //增加库存
  1684. $up_total_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET total = (total + " . (int)$quantity . ") where id={$goods_id} ";
  1685. M()->execute($up_total_sql);
  1686. //销量减少
  1687. $up_seller_count_sql = "update ".C('DB_PREFIX')."lionfish_comshop_goods SET seller_count = (seller_count - " . (int)$quantity . ") WHERE id = {$goods_id}";
  1688. M()->execute($up_seller_count_sql);
  1689. D('Seller/Redisorder')->bu_goods_quantity($goods_id,$quantity);
  1690. }
  1691. if(!empty($option))
  1692. {
  1693. if($type == 1)
  1694. {
  1695. $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}' ";
  1696. M()->execute($up_sku_total_sql);
  1697. } else if($type ==2){
  1698. $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}' ";
  1699. M()->execute($up_sku_total_sql);
  1700. D('Seller/Redisorder')->bu_goods_sku_quantity($goods_id,$quantity, $option);
  1701. }
  1702. }
  1703. //D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  1704. }
  1705. /**
  1706. 获取比较详细混合的商品信息
  1707. 可能会包含到分佣的情况
  1708. **/
  1709. public function get_goods_mixinfo($goods_id)
  1710. {
  1711. $need_data = array();
  1712. $goods_info = M('lionfish_comshop_goods')->field('credit as points,type,codes as model')->where( array('id' => $goods_id) )->find();
  1713. $commiss_info = M('lionfish_comshop_good_commiss')->where( array('goods_id' => $goods_id) )->find();
  1714. if( !empty($commiss_info) )
  1715. {
  1716. //涉及到会员分销等级,先放着
  1717. }else{
  1718. $goods_info['nocommission'] = 0;
  1719. $goods_info['hascommission'] = 0;
  1720. }
  1721. /**M('goods')->field(
  1722. 'points,commiss_fen_one_disc,
  1723. commiss_fen_two_disc,commiss_fen_three_disc,commiss_three_dan_disc,commiss_two_dan_disc,
  1724. commiss_one_dan_disc,store_id,type,model,image'
  1725. )->where( array('goods_id' => $goods_id) )->find();
  1726. **/
  1727. }
  1728. /**
  1729. * 生成核销订单二维码
  1730. * @param $hx_qrcode 订单核销码
  1731. * @return string
  1732. */
  1733. public function _get_commmon_hxqrcode($hx_qrcode)
  1734. {
  1735. $level = 3;
  1736. $size = 4;
  1737. Vendor('phpqrcode.phpqrcode');
  1738. $errorCorrectionLevel =intval($level) ;//容错级别
  1739. $matrixPointSize = intval($size);//生成图片大小
  1740. //图片地址
  1741. $image_dir = ROOT_PATH.'Uploads/image/';
  1742. $image_dir .= 'goods'.date('Y-m-d').'/';
  1743. RecursiveMkdir($image_dir);
  1744. $file_name = md5('qrcode_'.$hx_qrcode.time()).'.png';
  1745. //生成二维码图片
  1746. $object = new \QRcode();
  1747. $object->png($hx_qrcode, $image_dir.$file_name, $errorCorrectionLevel, $matrixPointSize, 2);
  1748. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  1749. if( $attachment_type_arr['value'] == 1 )
  1750. {
  1751. save_image_to_qiniu($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  1752. }else if( $attachment_type_arr['value'] == 2 ){
  1753. save_image_to_alioss($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  1754. }else if( $attachment_type_arr['value'] == 3 ){
  1755. $res = save_image_to_txyun($image_dir.$file_name,'Uploads/image/'.'goods'.date('Y-m-d').'/'.$file_name);
  1756. }
  1757. return 'goods'.date('Y-m-d').'/'.$file_name;
  1758. }
  1759. /**
  1760. * @author cy 2021-03-11
  1761. * @desc 生成邀新有礼二维码
  1762. * @param $invite_url
  1763. * @param string $back_color
  1764. * @param string $line_color
  1765. * @return string
  1766. */
  1767. public function _get_invite_qrcode($invite_url, $back_color="#ffffff", $line_color = "#000000"){
  1768. Vendor('phpqrcode.phpqrcode');
  1769. $object = new \QRcode();
  1770. $level = 3;
  1771. $size = 10;
  1772. $errorCorrectionLevel =intval($level) ;//容错级别
  1773. $matrixPointSize = intval($size);//生成图片大小
  1774. $time = date('Y-m-d');
  1775. //图片地址
  1776. $image_dir = ROOT_PATH.'Uploads/image/';
  1777. $image_dir .= 'invite/'.$time.'/';
  1778. RecursiveMkdir($image_dir);
  1779. //图片名称
  1780. $file_name = md5('invite_qrcode_'.time()).'.png';
  1781. $back_array = $this->hex2rgb_array($back_color);
  1782. $line_array = $this->hex2rgb_array($line_color);
  1783. //二维码生成
  1784. $object->pngcolor($invite_url, $image_dir.$file_name, $errorCorrectionLevel, $matrixPointSize, 2 , false, $back_array, $line_array);
  1785. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  1786. if( $attachment_type_arr['value'] == 1 )
  1787. {
  1788. save_image_to_qiniu($image_dir.$file_name,'Uploads/image/'.'invite/'.$time.'/'.$file_name);
  1789. }else if( $attachment_type_arr['value'] == 2 ){
  1790. save_image_to_alioss($image_dir.$file_name,'Uploads/image/'.'invite/'.$time.'/'.$file_name);
  1791. }else if( $attachment_type_arr['value'] == 3 ){
  1792. $res = save_image_to_txyun($image_dir.$file_name,'Uploads/image/'.'invite/'.$time.'/'.$file_name);
  1793. }
  1794. return 'invite/'.$time.'/'.$file_name;
  1795. }
  1796. /**
  1797. * 十六进制转RGB
  1798. * @param string $color 16进制颜色值
  1799. * @return array
  1800. */
  1801. function hex2rgb_array($color) {
  1802. $hexColor = str_replace('#', '', $color);
  1803. $lens = strlen($hexColor);
  1804. if ($lens != 3 && $lens != 6) {
  1805. return false;
  1806. }
  1807. $newcolor = '';
  1808. if ($lens == 3) {
  1809. for ($i = 0; $i < $lens; $i++) {
  1810. $newcolor .= $hexColor[$i] . $hexColor[$i];
  1811. }
  1812. } else {
  1813. $newcolor = $hexColor;
  1814. }
  1815. $hex = str_split($newcolor, 2);
  1816. $rgb = [];
  1817. foreach ($hex as $key => $vls) {
  1818. $rgb[] = hexdec($vls);
  1819. }
  1820. return $rgb;
  1821. }
  1822. public function _get_invite_wxqrcode($invite_url, $share_id = 0, $back_color="#ffffff", $line_color = "#000000")
  1823. {
  1824. $suffix = 'png';
  1825. $weixin_config = array();
  1826. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  1827. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  1828. $qrcode_rgb = $line_color;
  1829. $qrcode_arr = array();
  1830. if( !empty($qrcode_rgb) )
  1831. {
  1832. $qrcode_arr = $this->hex2rgb($qrcode_rgb);
  1833. }
  1834. //qrcode
  1835. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'] ,$weixin_config['appscert'] );
  1836. $weqrcode = $jssdk->getAllWeQrcode($invite_url, $share_id,$suffix=="png",$qrcode_arr);
  1837. //line_color
  1838. $time = date('Y-m-d');
  1839. //保存图片
  1840. $image_dir = ROOT_PATH.'Uploads/image/';
  1841. $image_dir .= 'invite/'.$time.'/';
  1842. RecursiveMkdir($image_dir);
  1843. $file_name = md5('invite_wxqrcode_'.$share_id.time()).'.'.$suffix;
  1844. //qrcode
  1845. file_put_contents($image_dir.$file_name, $weqrcode);
  1846. $attachment_type_arr = M('lionfish_comshop_config')->where( array('name' => 'attachment_type') )->find();
  1847. if( $attachment_type_arr['value'] == 1 )
  1848. {
  1849. save_image_to_qiniu($image_dir.$file_name,'Uploads/image/invite/'.$time.'/'.$file_name);
  1850. }else if( $attachment_type_arr['value'] == 2 ){
  1851. save_image_to_alioss($image_dir.$file_name,'Uploads/image/invite/'.$time.'/'.$file_name);
  1852. }else if( $attachment_type_arr['value'] == 3 ){
  1853. $res = save_image_to_txyun($image_dir.$file_name,'Uploads/image/invite/'.$time.'/'.$file_name);
  1854. }
  1855. return 'invite/'.$time.'/'.$file_name;
  1856. }
  1857. }