PingoodsModel.class.php 80 KB

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