CommunityController.class.php 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. class CommunityController extends CommonController {
  11. public function get_member_ziti_order()
  12. {
  13. $gpc = I('request.');
  14. $xq_member_id = $gpc['memberId'];
  15. $token = $gpc['token'];
  16. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  17. $member_id = $weprogram_token['member_id'];
  18. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  19. if( empty($member_info) )
  20. {
  21. echo json_encode( array('code' => 2) );
  22. die();
  23. }
  24. $community_info = D('Home/Front')->get_member_community_info($member_id);
  25. if( empty($community_info) && $member_info['pickup_id'] > 0 )
  26. {
  27. $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' =>$member_id ) )->find();
  28. if(!empty($parent_community_info))
  29. {
  30. $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
  31. }
  32. }
  33. if( empty($community_info) || $community_info['state'] != 1 )
  34. {
  35. echo json_encode( array('code' => 2) );
  36. die();
  37. }
  38. $where = ' and o.head_id = '.$community_info['id']." and o.member_id = ".$xq_member_id;
  39. $where .= ' and o.order_status_id = 4 ';
  40. $sql = "select o.order_id,o.order_num_alias,o.date_added,o.delivery,o.is_pin,o.is_zhuli,o.shipping_fare,o.voucher_credit,o.store_id,o.total,o.order_status_id,o.lottery_win,o.type,os.name as status_name,o.shipping_name,o.shipping_tel,o.payment_code "
  41. . " from ".C('DB_PREFIX')."lionfish_comshop_order as o ,
  42. ".C('DB_PREFIX')."lionfish_comshop_order_status as os
  43. where o.delivery != 'express' and o.delivery != 'hexiao' and o.order_status_id = os.order_status_id {$where}
  44. order by o.date_added desc ";
  45. $list = M()->query($sql);
  46. //createTime
  47. foreach($list as $key => $val)
  48. {
  49. $val['checked'] = 1;
  50. if($val['delivery'] == 'pickup')
  51. {
  52. //$val['total'] = round($val['total'],2) - round($val['voucher_credit'],2);
  53. }else{
  54. //$val['total'] = round($val['total'],2)+round($val['shipping_fare'],2) - round($val['voucher_credit'],2);
  55. }
  56. $val['createTime'] = date('Y-m-d H:i:s', $val['date_added']);
  57. // $val['delivery'] =='pickup'
  58. if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
  59. {
  60. $val['shipping_fare'] = '免运费';
  61. }else{
  62. $val['shipping_fare'] = '运费:'.$val['shipping_fare'];
  63. }
  64. if($val['order_status_id'] == 10)
  65. {
  66. $val['status_name'] = '等待退款';
  67. }
  68. else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
  69. {
  70. //delivery 6
  71. $val['status_name'] = '待自提';
  72. //已自提
  73. }
  74. else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
  75. {
  76. //delivery 6
  77. $val['status_name'] = '已自提';
  78. //已自提
  79. }
  80. else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
  81. {
  82. //等待开奖
  83. //一等奖
  84. if($val['lottery_win'] == 1)
  85. {
  86. $val['status_name'] = '一等奖';
  87. }else {
  88. $val['status_name'] = '等待开奖';
  89. }
  90. }
  91. else if($val['order_status_id'] == 2 && $val['type'] == 'lottery')
  92. {
  93. //等待开奖
  94. $val['status_name'] = '等待开奖';
  95. }
  96. $quantity = 0;
  97. $url = D('Home/Front')->get_config_by_name('shop_domain').'/';
  98. $goods_sql = "select order_id,order_goods_id,head_disc,member_disc,level_name,goods_id,is_pin,shipping_fare,name,goods_images,quantity,price,total,rela_goodsoption_valueid,is_refund_state,has_refund_money,has_refund_quantity"
  99. . " from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_id= ".$val['order_id']."";
  100. $goods_list = M()->query($goods_sql); //M()->query($goods_sql);
  101. foreach($goods_list as $kk => $vv)
  102. {
  103. //commision
  104. if($is_tuanz == 1){
  105. $community_order_info = M('lionfish_community_head_commiss_order')->where( array('head_id' => $community_info['id'],'order_goods_id' => $vv['order_goods_id']) )->find();
  106. if(!empty($community_order_info))
  107. {
  108. $vv['commision'] = $community_order_info['money'];
  109. }else{
  110. $vv['commision'] = 0;
  111. }
  112. }
  113. $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $vv['order_goods_id']) )->select();
  114. if( !empty($vv['goods_images']))
  115. {
  116. $goods_images = $url.resize($vv['goods_images'],400,400);
  117. if(is_array($goods_images))
  118. {
  119. $vv['goods_images'] = $vv['goods_images'];
  120. }else{
  121. $vv['goods_images']= $url.resize($vv['goods_images'],400,400) ;
  122. }
  123. }else{
  124. $vv['goods_images']= '';
  125. }
  126. $goods_filed = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $vv['goods_id']) )->find();
  127. $vv['orign_price'] = $goods_filed['price'];
  128. $quantity += $vv['quantity'];
  129. foreach($order_option_list as $option)
  130. {
  131. $vv['option_str'][] = $option['value'];
  132. }
  133. if( !isset($vv['option_str']) )
  134. {
  135. $vv['option_str'] = '';
  136. }else{
  137. $vv['option_str'] = implode(',', $vv['option_str']);
  138. }
  139. $vv['price'] = round($vv['price'],2);
  140. $vv['orign_price'] = round($vv['orign_price'],2);
  141. $vv['checked'] = 1;
  142. if( $vv['is_refund_state'] == 1 || ($vv['has_refund_money'] > 0 && $vv['has_refund_quantity'] > 0) )
  143. {
  144. $vv['is_refund_state'] = 1;
  145. $where = " order_id = '".$vv['order_id']."' and order_goods_id = '".$vv['order_goods_id']."' and state in (0,2,3) ";
  146. $refund_info = M('lionfish_comshop_order_refund')->field('ref_id,order_id,ref_money,real_refund_quantity,state')->where( $where )->find();
  147. if(!empty($refund_info)){
  148. $vv['refund_info'] = $refund_info;
  149. }else{
  150. $refund_info = array();
  151. $refund_info['order_id'] = $val['order_id'];
  152. $refund_info['ref_money'] = $vv['has_refund_money'];
  153. $refund_info['real_refund_quantity'] = $vv['has_refund_quantity'];
  154. $refund_info['state'] = 3;
  155. $vv['refund_info'] = $refund_info;
  156. }
  157. }
  158. $goods_list[$kk] = $vv;
  159. }
  160. $val['quantity'] = $quantity;
  161. if( empty($val['store_id']) )
  162. {
  163. $val['store_id'] = 1;
  164. }
  165. $store_info = array('s_true_name' =>'','s_logo' => '');
  166. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  167. $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  168. if( !empty($store_info['s_logo']))
  169. {
  170. $store_info['s_logo'] = $url .tomedia($store_info['s_logo']);
  171. }else{
  172. $store_info['s_logo'] = '';
  173. }
  174. $order_goods['store_info'] = $store_info;
  175. $val['store_info'] = $store_info;
  176. $val['goods_list'] = $goods_list;
  177. if($val['type'] == 'integral')
  178. {
  179. //暂时屏蔽积分
  180. //$integral_order = M('integral_order')->field('score')->where( array('order_id' => $val['order_id']) )->find();
  181. //$val['score'] = intval($integral_order['score']);
  182. }
  183. $val['total'] = round($val['total'],2);
  184. //货到付款订单
  185. if($val['payment_code'] == 'cashon_delivery'){
  186. $val['cashondelivery_code_img'] = D('Home/Front')->getCashonDeliveryCode();
  187. }
  188. $list[$key] = $val;
  189. }
  190. $need_data = array('code' => 0);
  191. if( !empty($list) )
  192. {
  193. $need_data['data'] = $list;
  194. }else {
  195. $need_data = array('code' => 1);
  196. }
  197. echo json_encode( $need_data );
  198. die();
  199. }
  200. public function get_community_zhitui_qrcode()
  201. {
  202. $_GPC = I('request.');
  203. $token = $_GPC['token'];
  204. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  205. $member_id = $weprogram_token['member_id'];
  206. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  207. if( empty($member_info) )
  208. {
  209. echo json_encode( array('code' => 1) );
  210. die();
  211. }
  212. $community_info = D('Home/Front')->get_member_community_info($member_id);
  213. if( empty($community_info) || $community_info['state'] != 1 )
  214. {
  215. echo json_encode( array('code' => 1) );
  216. die();
  217. }
  218. $head_id = $community_info['id'];
  219. $community_zhitui_qrcode_json = D('Home/Front')->get_config_by_name("community_zhitui_qrcode".$head_id);
  220. if( empty($community_zhitui_qrcode_json) )
  221. {
  222. $path = "lionfish_comshop/moduleA/groupCenter/apply";
  223. $zhitui_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  224. if( empty($zhitui_qrcod) )
  225. {
  226. $zhitui_qrcod = '';
  227. }else{
  228. $zhitui_qrcod = tomedia($zhitui_qrcod);
  229. $arr = array();
  230. $arr['qrcode'] = $zhitui_qrcod;
  231. $arr['express_time'] = time() + 600;
  232. $hd_key = "community_zhitui_qrcode".$head_id;
  233. D('Seller/Config')->update( array( $hd_key => serialize($arr)) );
  234. }
  235. echo json_encode( array('code' => 0, 'qrcode' => $zhitui_qrcod ) );
  236. die();
  237. }else{
  238. $community_zhitui_qrcode_arr = unserialize($community_zhitui_qrcode_json);
  239. if( $community_zhitui_qrcode_arr['express_time'] < time() )
  240. {
  241. $path = "lionfish_comshop/moduleA/groupCenter/apply";
  242. $zhitui_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  243. if( empty($zhitui_qrcod) )
  244. {
  245. $zhitui_qrcod = '';
  246. }else{
  247. $zhitui_qrcod = tomedia($zhitui_qrcod);
  248. $arr = array();
  249. $arr['qrcode'] = $zhitui_qrcod;
  250. $arr['express_time'] = time() + 600;
  251. $ky = "community_zhitui_qrcode".$head_id;
  252. D('Seller/Config')->update( array( $ky => serialize($arr) ) );
  253. }
  254. echo json_encode( array('code' => 0, 'qrcode' => $zhitui_qrcod ) );
  255. die();
  256. }else{
  257. echo json_encode( array('code' => 0, 'qrcode' => $community_zhitui_qrcode_arr['qrcode'] ) );
  258. die();
  259. }
  260. }
  261. }
  262. //------begin---
  263. /**
  264. 获取团长绑定核销人员二维码接口
  265. **/
  266. public function get_community_bind_member_qrcode()
  267. {
  268. $_GPC = I('request.');
  269. $token = $_GPC['token'];
  270. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  271. $member_id = $weprogram_token['member_id'];
  272. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  273. if( empty($member_info) )
  274. {
  275. echo json_encode( array('code' => 1) );
  276. die();
  277. }
  278. $community_info = D('Home/Front')->get_member_community_info($member_id);
  279. if( empty($community_info) || $community_info['state'] != 1 )
  280. {
  281. echo json_encode( array('code' => 1) );
  282. die();
  283. }
  284. $head_id = $community_info['id'];
  285. $community_memberbind_qrcode = D('Home/Front')->get_config_by_name('community_memberbind_qrcode'.$head_id);
  286. if( empty($community_memberbind_qrcode) )
  287. {
  288. $path = "lionfish_comshop/moduleA/groupCenter/bind_member_hexiao";
  289. $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  290. $data = array();
  291. $data['time'] = time();
  292. $data['hexiao_qrcod'] = $hexiao_qrcod;
  293. $kd_lcc = 'community_memberbind_qrcode'.$head_id;
  294. D('Seller/Config')->update( array( $kd_lcc => serialize($data) ) );
  295. echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_qrcod) ) );
  296. die();
  297. }else{
  298. $hexiao_data = unserialize($community_memberbind_qrcode);
  299. if($hexiao_data['time'] + 600 < time() )
  300. {
  301. $path = "lionfish_comshop/moduleA/groupCenter/bind_member_hexiao";
  302. $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  303. $data = array();
  304. $data['time'] = time();
  305. $data['hexiao_qrcod'] = $hexiao_qrcod;
  306. $ky = 'community_memberbind_qrcode'.$head_id;
  307. D('Seller/Config')->update( array( $ky => serialize($data) ) );
  308. echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_qrcod) ) );
  309. die();
  310. }else{
  311. echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_data['hexiao_qrcod']) ) );
  312. die();
  313. }
  314. }
  315. }
  316. /**
  317. 团长的核销人员列表
  318. **/
  319. public function get_community_hexiao_memberlist()
  320. {
  321. $_GPC = I('request.');
  322. $token = $_GPC['token'];
  323. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  324. $member_id = $weprogram_token['member_id'];
  325. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  326. if( empty($member_info) )
  327. {
  328. echo json_encode( array('code' => 1) );
  329. die();
  330. }
  331. $community_info = D('Home/Front')->get_member_community_info($member_id);
  332. if( empty($community_info) || $community_info['state'] != 1 )
  333. {
  334. echo json_encode( array('code' => 1) );
  335. die();
  336. }
  337. $head_id = $community_info['id'];
  338. $member_list = M()->query("select * from ".C('DB_PREFIX').
  339. "lionfish_comshop_community_pickup_member where community_id={$head_id} and state = 1 order by id desc ");
  340. if( empty($member_list) )
  341. {
  342. echo json_encode( array('code' => 1, 'log' => '暂时没有核销人员') );
  343. die();
  344. }else{
  345. foreach( $member_list as $key => $val )
  346. {
  347. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' =>$val['member_id'] ) )->find();
  348. $member_record_count_arr = M()->query(" select count(order_id) as count from ".C('DB_PREFIX')
  349. ."lionfish_comshop_community_pickup_member_record where member_id=".$val['member_id'] );
  350. $member_record_count = $member_record_count_arr[0]['count'];
  351. $val['avatar'] = $mb_info['avatar'];
  352. $val['username'] = $mb_info['username'];
  353. $val['member_record_count'] = $member_record_count;
  354. $member_list[$key] = $val;
  355. //ims_lionfish_comshop_community_pickup_member_record
  356. }
  357. echo json_encode( array('code' => 0, 'member_list' => $member_list) );
  358. die();
  359. }
  360. //ims_lionfish_comshop_community_pickup_member
  361. }
  362. /**
  363. 绑定
  364. **/
  365. public function bind_community_member_do()
  366. {
  367. $_GPC = I('request.');
  368. $token = $_GPC['token'];
  369. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  370. $member_id = $weprogram_token['member_id'];
  371. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  372. if( empty($member_info) )
  373. {
  374. echo json_encode( array('code' => 1) );
  375. die();
  376. }
  377. $name = $_GPC['name'];
  378. $mobile = $_GPC['mobile'];
  379. $community_id = $_GPC['community_id'];
  380. $is_in_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id) )->find();
  381. if( !empty($is_in_info) )
  382. {
  383. echo json_encode( array('code' => 0) );
  384. die();
  385. }
  386. //pickup_id
  387. //lionfish_comshop_community_pickup_member
  388. $is_in_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id ) )->find();
  389. if( !empty($is_in_info) )
  390. {
  391. echo json_encode( array('code' => 0) );
  392. die();
  393. }
  394. $ins_data = array();
  395. $ins_data['community_id'] = $community_id;
  396. $ins_data['member_id'] = $member_id;
  397. $ins_data['state'] = 1;
  398. $ins_data['remark'] = '前台扫码添加,姓名:'.$name.',手机号:'.$mobile;
  399. $ins_data['addtime'] = time();
  400. $pickup_id = M('lionfish_comshop_community_pickup_member')->add($ins_data);
  401. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('pickup_id' => $pickup_id ));
  402. echo json_encode( array('code' => 0) );
  403. die();
  404. }
  405. //2、查看会员核销记录的
  406. public function get_member_hexiao_orderlist()
  407. {
  408. $_GPC = I('request.');
  409. $token = $_GPC['token'];
  410. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  411. $member_id = $weprogram_token['member_id'];
  412. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  413. if( empty($member_info) )
  414. {
  415. echo json_encode( array('code' => 1) );
  416. die();
  417. }
  418. //lionfish_comshop_community_pickup_member_record
  419. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  420. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  421. $offset = ($page - 1)* $size;
  422. $where = " and member_id = {$member_id} ";
  423. $sql = "select *
  424. from ".C('DB_PREFIX')."lionfish_comshop_community_pickup_member_record
  425. where 1 {$where}
  426. order by id desc limit {$offset},{$size}";
  427. $list = M()->query($sql);
  428. if( !empty($list) )
  429. {
  430. foreach($list as $key => $val)
  431. {
  432. $mb_info = M('lionfish_comshop_member')->field('username,avatar')->where( array('member_id' =>$val['member_id'] ) )->find();
  433. $val['username'] = $mb_info['username'];
  434. $val['avatar'] = $mb_info['avatar'];
  435. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  436. $list[$key] = $val;
  437. }
  438. }
  439. if( empty($list) )
  440. {
  441. echo json_encode(array('code' => 1));
  442. die();
  443. }else{
  444. echo json_encode( array('code' =>0, 'data' => $list) );
  445. die();
  446. }
  447. }
  448. //------end----
  449. /***
  450. 团长对清单进行收货
  451. **/
  452. public function sub_head_delivery()
  453. {
  454. $gpc = I('request.');
  455. $token = $gpc['token'];
  456. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  457. $member_id = $weprogram_token['member_id'];
  458. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  459. if( empty($member_info) )
  460. {
  461. echo json_encode( array('code' => 1) );
  462. die();
  463. }
  464. $community_info = D('Home/Front')->get_member_community_info($member_id);
  465. if( empty($community_info) || $community_info['state'] != 1 )
  466. {
  467. echo json_encode( array('code' => 1) );
  468. die();
  469. }
  470. $head_id = $community_info['id'];
  471. $list_id = $gpc['list_id'];
  472. $list_info = M('lionfish_comshop_deliverylist')->where( array('id' => $list_id, 'head_id' => $head_id) )->find();
  473. if( !empty($list_info) )
  474. {
  475. M('lionfish_comshop_deliverylist')->where( array('id' => $list_id ) )->save( array('state' => 2,'head_get_time' => time() ) );
  476. //对订单操作,可以去提货了 load_model_class('frontorder')->send_order_operate($order_id);
  477. $order_ids_all = M('lionfish_comshop_deliverylist_order')->where( array('list_id' => $list_id ) )->select();
  478. if( !empty($order_ids_all) )
  479. {
  480. foreach($order_ids_all as $order_val)
  481. {
  482. $order_status_id_info = M('lionfish_comshop_order')->field('order_status_id')->where( array('order_id' => $order_val['order_id'] ) )->find();
  483. $order_status_id = $order_status_id_info['order_status_id'];
  484. //配送中才能
  485. if($order_status_id == 14)
  486. {
  487. $history_data = array();
  488. $history_data['order_id'] = $order_val['order_id'];
  489. $history_data['order_status_id'] = 4;
  490. $history_data['notify'] = 0;
  491. $history_data['comment'] = '前台团长签收配送清单';
  492. $history_data['date_added'] = time();
  493. M('lionfish_comshop_order_history')->add( $history_data );
  494. //send_order_operate
  495. D('Home/Frontorder')->send_order_operate($order_val['order_id']);
  496. }
  497. }
  498. }
  499. echo json_encode( array('code' => 0) );
  500. die();
  501. }else{
  502. echo json_encode( array('code' => 1) );
  503. die();
  504. }
  505. }
  506. /**
  507. 获取团长清单的商品列表
  508. **/
  509. public function get_head_deliverygoods()
  510. {
  511. $gpc = I('request.');
  512. $token = $gpc['token'];
  513. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  514. $member_id = $weprogram_token['member_id'];
  515. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  516. if( empty($member_info) )
  517. {
  518. echo json_encode( array('code' => 1) );
  519. die();
  520. }
  521. $community_info = D('Home/Front')->get_member_community_info($member_id);
  522. if( empty($community_info) || $community_info['state'] != 1 )
  523. {
  524. echo json_encode( array('code' => 1) );
  525. die();
  526. }
  527. $head_id = $community_info['id'];
  528. //lionfish_comshop_deliverylist_goods
  529. $list_id = $gpc['list_id'];
  530. $page = isset($gpc['page']) ? $gpc['page']:'1';
  531. $size = isset($gpc['size']) ? $gpc['size']:'20';
  532. $offset = ($page - 1)* $size;
  533. $where = " and list_id = {$list_id} ";
  534. $sql = "select *
  535. from ".C('DB_PREFIX')."lionfish_comshop_deliverylist_goods
  536. where 1 {$where}
  537. order by id desc limit {$offset},{$size}";
  538. $list = M()->query($sql);
  539. if( !empty($list) )
  540. {
  541. foreach($list as $key => $val)
  542. {
  543. $val['goods_image'] = tomedia($val['goods_image']);
  544. $list[$key] = $val;
  545. }
  546. }
  547. if( empty($list) )
  548. {
  549. echo json_encode(array('code' => 1));
  550. die();
  551. }else{
  552. echo json_encode( array('code' =>0, 'data' => $list) );
  553. die();
  554. }
  555. }
  556. /**
  557. 获取团长的清单
  558. **/
  559. public function get_head_deliverylist()
  560. {
  561. $gpc = I('request.');
  562. $token = $gpc['token'];
  563. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  564. $member_id = $weprogram_token['member_id'];
  565. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  566. if( empty($member_info) )
  567. {
  568. echo json_encode( array('code' => 1) );
  569. die();
  570. }
  571. $community_info = D('Home/Front')->get_member_community_info($member_id);
  572. if( empty($community_info) || $community_info['state'] != 1 )
  573. {
  574. echo json_encode( array('code' => 1) );
  575. die();
  576. }
  577. $head_id = $community_info['id'];
  578. $page = isset($gpc['page']) ? $gpc['page']:'1';
  579. $size = isset($gpc['size']) ? $gpc['size']:'6';
  580. $offset = ($page - 1)* $size;
  581. $where = " and head_id = {$head_id} ";
  582. $status = isset( $gpc['status'] ) ? $gpc['status']: -1;
  583. $kyw = isset( $gpc['keywords'] ) ? $gpc['keywords']: '';
  584. if($status >= 0)
  585. {
  586. $where .= " and state = {$status} ";
  587. } else {
  588. }
  589. if(!empty($kyw))
  590. {
  591. $where .= ' and (head_name like "%'.$kyw.'%" or head_mobile like "%'.$kyw.'%" or line_name like "%'.$kyw.'%" or clerk_name like "%'.$kyw.'%" or clerk_mobile like "%'.$kyw.'%" )';
  592. }
  593. $sql = "select *
  594. from ".C('DB_PREFIX')."lionfish_comshop_deliverylist
  595. where 1 {$where}
  596. order by id desc limit {$offset},{$size}";
  597. $list = M()->query($sql);
  598. if( !empty($list) )
  599. {
  600. foreach ($list as $key => &$val) {
  601. $val['express_time'] = $val['express_time'] ? date('Y-m-d H:i', $val['express_time']) : '';
  602. $val['head_get_time'] = $val['head_get_time'] ? date('Y-m-d H:i', $val['head_get_time']) : '';
  603. $val['create_time'] = $val['create_time'] ? date('Y-m-d H:i',$val['create_time']) : '';
  604. }
  605. }
  606. if( empty($list) )
  607. {
  608. echo json_encode(array('code' => 1));
  609. die();
  610. }else{
  611. echo json_encode( array('code' =>0, 'data' => $list) );
  612. die();
  613. }
  614. }
  615. //--
  616. public function headorderlist()
  617. {
  618. $gpc = I('request.');
  619. $token = $gpc['token'];
  620. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  621. $member_id = $weprogram_token['member_id'];
  622. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  623. if( empty($member_info) )
  624. {
  625. echo json_encode( array('code' => 1) );
  626. die();
  627. }
  628. $community_info = D('Home/Front')->get_member_community_info($member_id);
  629. if( empty($community_info) || $community_info['state'] != 1 )
  630. {
  631. echo json_encode( array('code' => 1) );
  632. die();
  633. }
  634. $head_id = $community_info['id'];
  635. $page = isset($gpc['page']) ? $gpc['page']:'1';
  636. $size = isset($gpc['size']) ? $gpc['size']:'6';
  637. $offset = ($page - 1)* $size;
  638. $where = " and co.head_id = {$head_id} ";
  639. $order_status = $gpc['order_status'];
  640. if($order_status == 1)
  641. {
  642. $where .= " and co.state = 0 ";
  643. } else if($order_status == 2){
  644. $where .= " and co.state = 1 ";
  645. }
  646. /*$sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name
  647. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  648. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  649. where co.order_goods_id = og.order_goods_id {$where}
  650. order by co.id desc limit {$offset},{$size}";*/
  651. $sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name,co.type
  652. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co left join
  653. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og on co.order_goods_id = og.order_goods_id
  654. where 1=1 {$where}
  655. order by co.id desc limit {$offset},{$size}";
  656. $list = M()->query($sql);
  657. if( !empty($list) )
  658. {
  659. foreach($list as $key => $val)
  660. {
  661. $val['total'] = sprintf("%.2f",$val['total']);
  662. $val['money'] = sprintf("%.2f",$val['money']);
  663. $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
  664. $order_info= M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id']) )->find();
  665. $val['order_num_alias'] = $order_info['order_num_alias'];
  666. if($val['type'] == 'tuijian'){
  667. $val['name'] = "推荐团长现金奖励";
  668. }
  669. $list[$key] = $val;
  670. }
  671. }
  672. if( empty($list) )
  673. {
  674. echo json_encode(array('code' => 1));
  675. die();
  676. }else{
  677. echo json_encode( array('code' =>0, 'data' => $list) );
  678. die();
  679. }
  680. }
  681. public function cashlist()
  682. {
  683. $gpc = I('request.');
  684. $token = $gpc['token'];
  685. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  686. $member_id = $weprogram_token['member_id'];
  687. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  688. if( empty($member_info) )
  689. {
  690. echo json_encode( array('code' => 1) );
  691. die();
  692. }
  693. $community_info = D('Home/Front')->get_member_community_info($member_id);
  694. if( empty($community_info) || $community_info['state'] != 1 )
  695. {
  696. echo json_encode( array('code' => 1) );
  697. die();
  698. }
  699. $page = isset($gpc['page']) ? $gpc['page']:'1';
  700. $size = isset($gpc['size']) ? $gpc['size']:'6';
  701. $offset = ($page - 1)* $size;
  702. //begin select
  703. $sql = "select *
  704. from ".C('DB_PREFIX')."lionfish_community_head_tixian_order
  705. where head_id =".$community_info['id']." and member_id={$member_id} order by id desc limit {$offset},{$size}";
  706. $list = M()->query($sql);
  707. foreach($list as $key => $val)
  708. {
  709. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  710. $val['id'] = sprintf("%04d", $val['id']);
  711. $list[$key] = $val;
  712. }
  713. if( empty($list) )
  714. {
  715. echo json_encode( array('code' => 1) );
  716. die();
  717. } else{
  718. echo json_encode( array('code' => 0, 'data' => $list) );
  719. die();
  720. }
  721. //ims_
  722. }
  723. public function get_community_member_orderlist()
  724. {
  725. $gpc = I('request.');
  726. $token = $gpc['token'];
  727. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  728. $member_id = $weprogram_token['member_id'];
  729. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  730. if( empty($member_info) )
  731. {
  732. echo json_encode( array('code' => 1) );
  733. die();
  734. }
  735. $community_info = D('Home/Front')->get_member_community_info($member_id);
  736. if( empty($community_info) && $member_info['pickup_id'] > 0 )
  737. {
  738. $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id ) )->find();
  739. if(!empty($parent_community_info))
  740. {
  741. $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
  742. }
  743. }
  744. if( empty($community_info) || $community_info['state'] != 1 )
  745. {
  746. echo json_encode( array('code' => 1) );
  747. die();
  748. }
  749. $page = isset($gpc['page']) ? $gpc['page']:'1';
  750. $size = isset($gpc['size']) ? $gpc['size']:'20';
  751. $offset = ($page - 1)* $size;
  752. //begin select
  753. $where = ' and h.head_id = '.$community_info['id'];
  754. //date: that.data.date,
  755. //searchKey: that.data.searchKey,
  756. if( isset($gpc['date']) && !empty($gpc['date']) )
  757. {
  758. }
  759. if( isset($gpc['searchKey']) && !empty($gpc['searchKey']) )
  760. {
  761. $keywords = $gpc['searchKey'];
  762. $mb_order_list = M()->query( "select member_id from ". C('DB_PREFIX')."lionfish_comshop_order
  763. where head_id=".$community_info['id']." and (shipping_tel like '%{$keywords}%' or shipping_name like '%{$keywords}%' ) " );
  764. $member_id_ids = array();
  765. if( !empty($mb_order_list) ){
  766. foreach($mb_order_list as $val)
  767. {
  768. $member_id_ids[] = $val['member_id'];
  769. }
  770. }
  771. if( !empty($member_id_ids) )
  772. {
  773. $member_id_ids_str = implode(',', $member_id_ids);
  774. $where .=" and (m.username like '%{$keywords}%' or h.member_id in({$member_id_ids_str}) ) ";
  775. }else{
  776. $where .=" and (m.username like '%{$keywords}%' ) ";
  777. }
  778. }
  779. $sql = "select h.member_id,h.id ,m.avatar, m.username ,("."select count(order_id) from ".C('DB_PREFIX')."lionfish_comshop_order
  780. where order_status_id =4 and delivery!='express' and delivery!='hexiao' and member_id=m.member_id and head_id= ".$community_info['id'].") as m_count
  781. from ".C('DB_PREFIX')."lionfish_community_history as h left join ".C('DB_PREFIX')."lionfish_comshop_member as m on h.member_id = m.member_id
  782. where 1 {$where}
  783. group by h.member_id order by m_count desc, h.id desc limit {$offset},{$size}";
  784. $list = M()->query($sql);
  785. //ims_lionfish_comshop_order
  786. $need_list = array();
  787. foreach($list as $key => $val)
  788. {
  789. $mb_info_ck = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->find();
  790. if( empty($mb_info_ck) )
  791. {
  792. continue;
  793. }
  794. $last_order_info = M('lionfish_comshop_order')->field('shipping_tel,shipping_name')->where( array('head_id' => $community_info['id'],'member_id' =>$val['member_id'] ) )->order('order_id desc')->find();
  795. if( empty($last_order_info) )
  796. {
  797. $val['mobile'] = '未下单';
  798. }else{
  799. $val['mobile'] = $last_order_info['shipping_tel'];
  800. }
  801. $val['shipping_name'] = $last_order_info['shipping_name'];
  802. $order_count = M('lionfish_comshop_order')->where( array('head_id' => $community_info['id'],'member_id' => $val['member_id'],'order_status_id' => 4) )->where("delivery!='express' and delivery!='hexiao'")->count();
  803. //$val['username'] = $member_info['username'];
  804. //$val['avatar'] = $member_info['avatar'];
  805. $val['order_count'] = $order_count;
  806. $list[$key] = $val;
  807. $need_list[$key] = $val;
  808. }
  809. $close_community_delivery_orders = D('Home/Front')->get_config_by_name('close_community_delivery_orders');
  810. if( !empty($need_list) )
  811. {
  812. $list = array();
  813. $i =0;
  814. foreach($need_list as $key => $val)
  815. {
  816. $list[$i] = $val;
  817. $i ++;
  818. }
  819. echo json_encode( array('code' => 0, 'data' => $list , 'close_community_delivery_orders'=>$close_community_delivery_orders ) );
  820. die();
  821. }else {
  822. echo json_encode( array('code' => 1) );
  823. die();
  824. }
  825. }
  826. public function bind_community_info()
  827. {
  828. $gpc = I('request.');
  829. $token = $gpc['token'];
  830. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  831. $member_id = $weprogram_token['member_id'];
  832. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  833. if( empty($member_info) )
  834. {
  835. echo json_encode( array('code' => 1) );
  836. die();
  837. }
  838. $community_info = D('Home/Front')->get_member_community_info($member_id);
  839. if( empty($community_info) || $community_info['state'] != 1 )
  840. {
  841. echo json_encode( array('code' => 1) );
  842. die();
  843. }
  844. $cardname = $gpc['cardname'];
  845. $cardaccount = $gpc['cardaccount'];
  846. $cardno = $gpc['cardno'];
  847. //ims_
  848. //pdo_update('lionfish_community_head', $data, array('id' => $head_info['id']));
  849. $data = array();
  850. $data['bankname'] = $cardname;
  851. $data['bankaccount'] = $cardaccount;
  852. $data['bankusername'] = $cardno;
  853. M('lionfish_community_head_commiss')->where( array('head_id' => $community_info['id']) )->save( $data );
  854. echo json_encode( array('code' => 0) );
  855. die();
  856. }
  857. public function get_community_info()
  858. {
  859. $gpc = I('request.');
  860. $token = $gpc['token'];
  861. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  862. $member_id = $weprogram_token['member_id'];
  863. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  864. if( empty($member_info) )
  865. {
  866. echo json_encode( array('code' => 1) );
  867. die();
  868. }
  869. $community_info = D('Home/Front')->get_member_community_info($member_id);
  870. if( empty($community_info) || $community_info['state'] != 1 )
  871. {
  872. echo json_encode( array('code' => 1) );
  873. die();
  874. }
  875. $community_info['re_id'] = sprintf("%05d", $community_info['id']);
  876. $head_id = $community_info['id'];
  877. //已获佣金情况
  878. $commission_info = D('Seller/Community')->get_head_commission_info($member_id, $head_id);
  879. //总订单数量
  880. $total_order_count = D('Home/Frontorder')->get_community_head_order_count($head_id);
  881. //待配送 1 1
  882. $wait_send_count = M('lionfish_comshop_order')->where( array('order_status_id' => 1, 'head_id' => $head_id) )->where(" type != 'ignore' ")->count();
  883. //待签收 14 14
  884. $wait_qianshou_count = M('lionfish_comshop_order')->where( array('order_status_id' => 14, 'head_id' => $head_id) )->count();
  885. //待提货 4 4
  886. $wait_tihuo_count = M('lionfish_comshop_order')->where( array('order_status_id' => 4, 'head_id' => $head_id) )->count();
  887. //完成6-》 (6,11)
  888. $has_success_count = M('lionfish_comshop_order')->where( array('order_status_id' => array('in','6,11'), 'head_id' => $head_id) )->count();
  889. //会员数量
  890. $total_member_count = D('Seller/Community')->get_community_head_member_count($head_id);
  891. //预计佣金 state=0
  892. $pre_total_money = M('lionfish_community_head_commiss_order')->where( array('state' => 0,'head_id' => $head_id) )->sum('money');
  893. if( empty($pre_total_money) )
  894. {
  895. $pre_total_money = 0;
  896. }
  897. //退配送费
  898. $refund_shipping_fare = 0;
  899. $refund_shipping_sql = "SELECT SUM( refund_shipping_fare ) as refund_shipping_fare "
  900. . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund ogf, ".C('DB_PREFIX')."lionfish_community_head_commiss_order oco "
  901. . " WHERE ogf.order_id = oco.order_id "
  902. . " AND oco.head_id = ".$head_id
  903. . " AND oco.state = 0 "
  904. . " AND oco.add_shipping_fare > 0 ";
  905. $refund_shippings = M()->query($refund_shipping_sql);
  906. if(!empty($refund_shippings)){
  907. $refund_shipping_fare = $refund_shippings[0]['refund_shipping_fare'];
  908. }
  909. $pre_total_money = $pre_total_money - $refund_shipping_fare;
  910. $commission_info['mix_total_money'] = $pre_total_money + $commission_info['money'] + $commission_info['dongmoney'] + $commission_info['getmoney'];
  911. $today_time = strtotime( date('Y-m-d').' 00:00:00' );
  912. //今日订单总数
  913. $today_order_count = M('lionfish_comshop_order')->where("head_id={$head_id} and date_added>={$today_time}")->count();
  914. //今日有效订单
  915. $today_effect_order_count = M('lionfish_comshop_order')->where( "order_status_id not in(3,5,7,12) and head_id={$head_id} and date_added>={$today_time} " )->count();
  916. //1、销售额:团长下面今日订单额度的总和,当日订单总数页面的总和 TODO..
  917. $seven_pay_where = " and head_id ={$head_id} and pay_time >= {$today_time} and order_status_id in (1,4,6,11,14) ";
  918. $seven_pay_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $seven_pay_where);
  919. $head_today_pay_money = empty($seven_pay_money_info['total']) ? 0:$seven_pay_money_info['total'];
  920. $head_today_pay_money = sprintf("%.2f",$head_today_pay_money);
  921. //2、新增会员数:团长新增的用户统计 TODO..
  922. $sql_count = "select count(h.id) as count from ".C('DB_PREFIX').
  923. "lionfish_community_history as h, ".C('DB_PREFIX')."lionfish_comshop_member as m where m.member_id=h.member_id and h.head_id={$head_id} and m.create_time>={$today_time} ";
  924. $today_add_head_member_arr = M()->query($sql_count);
  925. $today_add_head_member = $today_add_head_member_arr[0]['count'];
  926. //3.售后订单(笔):今日团长下面,申请售后的订单
  927. $sql_count = "select count(ref_id) as count from ".C('DB_PREFIX').
  928. "lionfish_comshop_order_refund where head_id={$head_id} and addtime>={$today_time} ";
  929. $today_after_sale_order_count_arr = M()->query($sql_count);
  930. $today_after_sale_order_count = $today_after_sale_order_count_arr[0]['count'];
  931. //4、今日访客:统计今日浏览团长商城的用户数量 TODO..
  932. $sql_count = "select count(id) as count from ".C('DB_PREFIX').
  933. "lionfish_community_history where head_id={$head_id} and addtime>={$today_time} ";
  934. $today_invite_head_member_arr = M()->query($sql_count);
  935. $today_invite_head_member = $today_invite_head_member_arr[0]['count'];
  936. //今日付款人数
  937. $sql_count = "select order_id from ".C('DB_PREFIX')."lionfish_comshop_order where head_id={$head_id} and pay_time>={$today_time} group by member_id ";
  938. $today_pay_order_list = M()->query($sql_count);
  939. $today_pay_order_count = count($today_pay_order_list);
  940. //今日预计佣金
  941. //$today_pre_total_money = M('lionfish_community_head_commiss_order')->where( " state=0 and head_id={$head_id} and addtime>={$today_time}" )->sum('money');
  942. $pre_sql = "SELECT SUM( co.money ) as money "
  943. . "FROM ".C('DB_PREFIX')."lionfish_community_head_commiss_order AS co "
  944. . "LEFT JOIN ".C('DB_PREFIX')."lionfish_comshop_order AS o ON co.order_id = o.order_id"
  945. . " WHERE co.head_id = ".$head_id
  946. . " AND co.addtime >= ".$today_time
  947. . " AND o.order_status_id not in (3,5,7,12) and co.state != 2 ";
  948. $today_pre_total_moneys = M()->query($pre_sql);
  949. if(!empty($today_pre_total_moneys)){
  950. $today_pre_total_money = $today_pre_total_moneys[0]['money'];
  951. }
  952. if(empty($today_pre_total_money))
  953. {
  954. $today_pre_total_money = 0;
  955. }
  956. //退配送费
  957. $today_refund_shipping_fare = 0;
  958. $today_refund_shipping_sql = "SELECT SUM( refund_shipping_fare ) as refund_shipping_fare "
  959. . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund ogf, ".C('DB_PREFIX')."lionfish_community_head_commiss_order oco "
  960. . " WHERE ogf.order_id = oco.order_id "
  961. . " AND oco.head_id = ".$head_id
  962. . " AND oco.state = 0 "
  963. . " AND oco.addtime >= '".$today_time."'"
  964. . " AND oco.add_shipping_fare > 0 ";
  965. $today_refund_shippings = M()->query($today_refund_shipping_sql);
  966. if(!empty($today_refund_shippings)){
  967. $today_refund_shipping_fare = $today_refund_shippings[0]['refund_shipping_fare'];
  968. }
  969. $today_pre_total_money = $today_pre_total_money - $today_refund_shipping_fare;
  970. //今日预计佣金+得到佣金
  971. $today_all_total_money = M('lionfish_community_head_commiss_order')->where( "(state=0 or state =1) and head_id={$head_id} and addtime>={$today_time}" )->sum('money');
  972. if(empty($today_all_total_money))
  973. {
  974. $today_all_total_money = 0;
  975. }
  976. $today_all_total_money = sprintf("%.2f", $today_all_total_money);
  977. $month_day = date('Y-m').'-01 00:00:00';
  978. $month_time = strtotime($month_day);
  979. //本月收入 and (state=0 or state =1)
  980. $month_pre_total_money = M('lionfish_community_head_commiss_order')->where( "head_id={$head_id} and (state=0 or state =1) and addtime>={$month_time}" )->sum('money');
  981. if(empty($month_pre_total_money))
  982. {
  983. $month_pre_total_money = 0;
  984. }
  985. /**待确认佣金*/
  986. //$wait_sub_total_money = M('lionfish_community_head_commiss_order')->where( "head_id={$head_id} and state=0" )->sum('money');
  987. $sql = "select sum( co.money ) as money from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  988. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  989. where co.order_goods_id = og.order_goods_id and og.is_refund_state = 0 and co.state = 0 and co.head_id = ".$head_id." order by co.id desc ";
  990. $pre_total_money_list = M()->query($sql);
  991. $wait_sub_total_money = $pre_total_money_list[0]['money'];
  992. if( empty($wait_sub_total_money) )
  993. {
  994. $wait_sub_total_money = 0;
  995. }
  996. //提现中
  997. $dongmoney = M('lionfish_community_head_tixian_order')->where( array('head_id' => $head_id, 'state' => 0) )->sum('money');
  998. if( empty($dongmoney) )
  999. {
  1000. $dongmoney = 0 ;
  1001. }
  1002. /**已成功提现金额**/
  1003. $tixian_sucess_money = M('lionfish_community_head_tixian_order')->where( array('head_id' => $head_id, 'state' => 1) )->sum('money');
  1004. if( empty($tixian_sucess_money) )
  1005. {
  1006. $tixian_sucess_money = 0;
  1007. }
  1008. $head_commiss_tixianway_yuer = D('Home/Front')->get_config_by_name('head_commiss_tixianway_yuer');
  1009. $head_commiss_tixianway_weixin = D('Home/Front')->get_config_by_name('head_commiss_tixianway_weixin');
  1010. $head_commiss_tixianway_alipay = D('Home/Front')->get_config_by_name('head_commiss_tixianway_alipay');
  1011. $head_commiss_tixianway_bank = D('Home/Front')->get_config_by_name('head_commiss_tixianway_bank');
  1012. $community_info['head_commiss_tixianway_yuer'] = empty($head_commiss_tixianway_yuer) ? 1 : ($head_commiss_tixianway_yuer == 2 ? 1:0);
  1013. $community_info['head_commiss_tixianway_weixin'] = empty($head_commiss_tixianway_weixin) ? 1 : ($head_commiss_tixianway_weixin == 2 ? 1:0);
  1014. $community_info['head_commiss_tixianway_alipay'] = empty($head_commiss_tixianway_alipay) ? 1 : ($head_commiss_tixianway_alipay == 2 ? 1:0);
  1015. $community_info['head_commiss_tixianway_bank'] = empty($head_commiss_tixianway_bank) ? 1 : ($head_commiss_tixianway_bank == 2 ? 1:0);
  1016. //上一微信真实姓名 lionfish_community_head_tixian_order
  1017. $last_weixin_realname = "";
  1018. //C('DB_PREFIX')
  1019. $last_weixin_info = M('lionfish_community_head_tixian_order')->where( array("member_id={$member_id} and head_id={$head_id} and type=2") )->find();
  1020. if( !empty($last_weixin_info) )
  1021. {
  1022. $last_weixin_realname = $last_weixin_info['bankusername'];
  1023. }
  1024. //上一支付宝账号
  1025. $last_alipay_name = '';
  1026. $last_alipay_account = '';
  1027. $last_alipay_info = M('lionfish_community_head_tixian_order')->where("member_id={$member_id} and head_id={$head_id} and type=3")->find();
  1028. if( !empty($last_alipay_info) )
  1029. {
  1030. $last_alipay_name = $last_alipay_info['bankusername'];
  1031. $last_alipay_account = $last_alipay_info['bankaccount'];
  1032. }
  1033. //上一银行卡信息
  1034. $last_bank_bankname = '';
  1035. $last_bank_account = '';
  1036. $last_bank_name = '';
  1037. $last_bank_info = M('lionfish_community_head_tixian_order')->where( "member_id={$member_id} and head_id={$head_id} and type=4" )->find();
  1038. if( !empty($last_bank_info) )
  1039. {
  1040. $last_bank_bankname = $last_bank_info['bankname'];
  1041. $last_bank_account = $last_bank_info['bankaccount'];
  1042. $last_bank_name = $last_bank_info['bankusername'];
  1043. }
  1044. $community_info['last_weixin_realname'] = $last_weixin_realname;
  1045. $community_info['last_alipay_name'] = $last_alipay_name;
  1046. $community_info['last_alipay_account'] = $last_alipay_account;
  1047. $community_info['last_bank_bankname'] = $last_bank_bankname;
  1048. $community_info['last_bank_account'] = $last_bank_account;
  1049. $community_info['last_bank_name'] = $last_bank_name;
  1050. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1051. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1052. $level_list = array(
  1053. 0 => array('levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money )
  1054. );
  1055. $hd_level_list = M('lionfish_comshop_community_head_level')->where(1)->select();
  1056. if( !empty($hd_level_list) )
  1057. {
  1058. foreach( $hd_level_list as $val )
  1059. {
  1060. $tmp = array();
  1061. $tmp['levelname'] = $val['levelname'];//等级名称
  1062. $tmp['commission'] = $val['commission'];//分佣比例
  1063. $level_list[$val['id']] = $tmp;
  1064. }
  1065. }
  1066. $is_show_head_level = D('Home/Front')->get_config_by_name('is_show_head_level');
  1067. $community_info['is_show_head_level'] = $is_show_head_level;
  1068. $community_info['head_level_info'] = $level_list[ $community_info['level_id'] ];
  1069. // 接龙开关
  1070. $is_open_solitaire = D('Home/Front')->get_config_by_name('is_open_solitaire');
  1071. $is_show_community_ranking = D('Home/Front')->get_config_by_name('is_show_community_ranking');
  1072. //是否显示团长排行, 0不显示,1显示
  1073. $is_show_community_ranking = empty($is_show_community_ranking) ? 0 : $is_show_community_ranking;
  1074. $result = array();
  1075. $result['code'] = 0;
  1076. $result['member_info'] = $member_info;
  1077. $result['community_info'] = $community_info;
  1078. $result['commission_info'] = $commission_info;
  1079. $result['total_order_count'] = $total_order_count;
  1080. $result['total_member_count'] = $total_member_count;
  1081. $result['today_order_count'] = $today_order_count;
  1082. $result['today_effect_order_count'] = $today_effect_order_count;
  1083. $result['today_all_total_money'] = $today_all_total_money;
  1084. $result['today_pay_order_count'] = $today_pay_order_count;
  1085. $result['today_pre_total_money'] = $today_pre_total_money;
  1086. $result['month_pre_total_money'] = $month_pre_total_money;
  1087. $result['pre_total_money'] = $pre_total_money;
  1088. $result['wait_sub_total_money'] = $wait_sub_total_money;
  1089. $result['dongmoney'] = $dongmoney;
  1090. $result['tixian_sucess_money'] = $tixian_sucess_money;
  1091. $result['wait_send_count'] = $wait_send_count;
  1092. $result['wait_qianshou_count'] = $wait_qianshou_count;
  1093. $result['wait_tihuo_count'] = $wait_tihuo_count;
  1094. $result['has_success_count'] = $has_success_count;
  1095. $result['head_today_pay_money'] = $head_today_pay_money;//今日销售额
  1096. $result['today_add_head_member'] = $today_add_head_member;//今日新增会员数
  1097. $result['today_after_sale_order_count'] = $today_after_sale_order_count;//今日售后订单
  1098. $result['today_invite_head_member'] = $today_invite_head_member;//今日访客
  1099. $result['is_show_community_ranking'] = $is_show_community_ranking;//团长排行
  1100. $result['is_open_solitaire'] = $is_open_solitaire;
  1101. $community_tixian_fee = D('Home/Front')->get_config_by_name('community_tixian_fee');
  1102. $community_min_money = D('Home/Front')->get_config_by_name('community_min_money');
  1103. if( empty($community_min_money) )
  1104. {
  1105. $community_min_money = 0;
  1106. }
  1107. if( empty($community_tixian_fee) )
  1108. {
  1109. $community_tixian_fee = 0;
  1110. }
  1111. $result['community_tixian_fee'] = $community_tixian_fee;
  1112. $result['community_min_money'] = $community_min_money;
  1113. $open_community_addhexiaomember = D('Home/Front')->get_config_by_name('open_community_addhexiaomember');
  1114. if( empty($open_community_addhexiaomember) )
  1115. {
  1116. $open_community_addhexiaomember = 0;
  1117. }
  1118. $result['open_community_addhexiaomember'] = $open_community_addhexiaomember;
  1119. //团长等级
  1120. $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve');
  1121. if( empty($open_community_head_leve) )
  1122. {
  1123. $open_community_head_leve = 0;
  1124. }
  1125. $result['open_community_head_leve'] = $open_community_head_leve;
  1126. $head_commiss_tixian_publish = D('Home/Front')->get_config_by_name('head_commiss_tixian_publish');
  1127. $result['head_commiss_tixian_publish'] = htmlspecialchars_decode( $head_commiss_tixian_publish );
  1128. $is_need_subscript = 0;
  1129. $need_subscript_template = array();
  1130. $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'apply_tixian') )->find();
  1131. if( empty($apply_tixian_info) )
  1132. {
  1133. $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  1134. if( !empty($weprogram_subtemplate_apply_tixian) )
  1135. {
  1136. $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
  1137. }
  1138. }
  1139. if( !empty($need_subscript_template) )
  1140. {
  1141. $is_need_subscript = 1;
  1142. }
  1143. $result['is_need_subscript'] = $is_need_subscript;
  1144. $result['need_subscript_template'] = $need_subscript_template;
  1145. // 分享信息
  1146. $result['shop_index_share_title'] = D('Home/Front')->get_config_by_name('shop_index_share_title');
  1147. $shop_index_share_image = D('Home/Front')->get_config_by_name('shop_index_share_image');
  1148. $result['shop_index_share_image'] = "";
  1149. if($shop_index_share_image) {
  1150. $result['shop_index_share_image'] = tomedia($shop_index_share_image);
  1151. }
  1152. echo json_encode( $result );
  1153. die();
  1154. }
  1155. //begin
  1156. /**
  1157. 获取团长的下级列表接口
  1158. **/
  1159. public function get_head_child_headlist()
  1160. {
  1161. $gpc = I('request.');
  1162. $_GPC = I('request.');
  1163. $token = $gpc['token'];
  1164. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1165. $member_id = $weprogram_token['member_id'];
  1166. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1167. if( empty($member_info) )
  1168. {
  1169. echo json_encode( array('code' => 1) );
  1170. die();
  1171. }
  1172. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1173. if( empty($community_info) || $community_info['state'] != 1 )
  1174. {
  1175. echo json_encode( array('code' => 1) );
  1176. die();
  1177. }
  1178. $head_id = $community_info['id'];
  1179. //...
  1180. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  1181. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  1182. $offset = ($page - 1)* $size;
  1183. //begin select
  1184. //$where = ' and head_id = '.$head_id;
  1185. $level = isset($_GPC['level']) ? $_GPC['level']: 1;
  1186. $level_1_ids = array();
  1187. $level_2_ids = array();
  1188. $level_3_ids = array();
  1189. $head_id_arr = array($head_id);
  1190. if( $level == 1 )
  1191. {
  1192. $list = array();
  1193. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
  1194. where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
  1195. $list = M()->query($sql);
  1196. foreach( $list as $vv )
  1197. {
  1198. $level_1_ids[] = $vv['id'];
  1199. }
  1200. }else if( $level == 2 )
  1201. {
  1202. $list = array();
  1203. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
  1204. where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
  1205. $list1 = M()->query($sql);
  1206. if( !empty($list1) )
  1207. {
  1208. foreach( $list1 as $vv )
  1209. {
  1210. $level_1_ids[] = $vv['id'];
  1211. }
  1212. $level_sql2 =" select * from ".C('DB_PREFIX').
  1213. "lionfish_community_head where
  1214. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1215. where agent_id ={$head_id} order by id desc ) order by id desc ";
  1216. $list2 = M()->query($level_sql2);
  1217. if( !empty($list2) || !empty($level_1_ids))
  1218. {
  1219. foreach( $list2 as $vv )
  1220. {
  1221. $level_2_ids[] = $vv['id'];
  1222. }
  1223. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  1224. if(!empty($level_2_ids))
  1225. {
  1226. foreach($level_2_ids as $vv)
  1227. {
  1228. $need_ids[] = $vv;
  1229. }
  1230. }
  1231. $sql =" select * from ".C('DB_PREFIX').
  1232. "lionfish_community_head where
  1233. id in (".implode(',', $need_ids ).") order by id desc limit {$offset},{$size}";
  1234. $list = M()->query($sql);
  1235. }
  1236. }
  1237. }else if( $level == 3 ){
  1238. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
  1239. where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
  1240. $list1 = M()->query($sql);
  1241. if( !empty($list1) )
  1242. {
  1243. foreach( $list1 as $vv )
  1244. {
  1245. $level_1_ids[] = $vv['id'];
  1246. }
  1247. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  1248. $level_sql2 =" select * from ".C('DB_PREFIX').
  1249. "lionfish_community_head where
  1250. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1251. where agent_id ={$head_id} order by id desc ) order by id desc ";
  1252. $list2 = M()->query($level_sql2);
  1253. if( !empty($list2) || !empty($level_1_ids))
  1254. {
  1255. foreach( $list2 as $vv )
  1256. {
  1257. $level_2_ids[] = $vv['id'];
  1258. }
  1259. if(!empty($level_2_ids))
  1260. {
  1261. foreach($level_2_ids as $vv)
  1262. {
  1263. $need_ids[] = $vv;
  1264. }
  1265. }
  1266. }
  1267. $level_sql3 =" select * from ".C('DB_PREFIX').
  1268. "lionfish_community_head where
  1269. agent_id in (".implode(',', $need_ids).") order by id desc ";
  1270. $list3 = M()->query($level_sql3);
  1271. if( !empty($list3) )
  1272. {
  1273. foreach( $list3 as $vv )
  1274. {
  1275. $level_3_ids[] = $vv['id'];
  1276. }
  1277. if(!empty($level_3_ids))
  1278. {
  1279. foreach($level_3_ids as $vv)
  1280. {
  1281. $need_ids[] = $vv;
  1282. }
  1283. }
  1284. }
  1285. $level_sql3 =" select * from ".C('DB_PREFIX').
  1286. "lionfish_community_head where id in (".implode(',',$need_ids).") order by id desc limit {$offset},{$size}";
  1287. $list = M()->query($level_sql3);
  1288. }
  1289. }
  1290. //---------等级
  1291. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1292. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1293. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1294. $list_default = array(
  1295. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1296. );
  1297. $community_head_level = array_merge($list_default, $community_head_level);
  1298. $level_id_to_name = array( 0=> empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname );
  1299. foreach($community_head_level as $kk => $vv)
  1300. {
  1301. $level_id_to_name[$vv['id']] = $vv['levelname'];
  1302. }
  1303. //---------等级
  1304. $level_list = array();
  1305. $need_list = array();
  1306. if( !empty($list) ){
  1307. foreach($list as $key => $val)
  1308. {
  1309. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id'] ) )->find();
  1310. $val['level_name'] = $level_id_to_name[ $val['level_id'] ];
  1311. $val['avatar'] = $mb_info['avatar'];
  1312. $val['username'] = $mb_info['username'];
  1313. $val['apptime'] = date('Y-m-d H:i:s', $val['apptime']);
  1314. $need_list[$key] = $val;
  1315. }
  1316. }
  1317. if( !empty($need_list) )
  1318. {
  1319. echo json_encode( array('code' => 0, 'data' => $need_list) );
  1320. die();
  1321. }else {
  1322. echo json_encode( array('code' => 1) );
  1323. die();
  1324. }
  1325. }
  1326. /**
  1327. 获取团长分销账户信息情况
  1328. **/
  1329. public function get_head_distribute_info()
  1330. {
  1331. $gpc = I('request.');
  1332. $_GPC = I('request.');
  1333. $token = $gpc['token'];
  1334. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1335. $member_id = $weprogram_token['member_id'];
  1336. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  1337. if( empty($member_info) )
  1338. {
  1339. echo json_encode( array('code' => 1) );
  1340. die();
  1341. }
  1342. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1343. if( empty($community_info) || $community_info['state'] != 1 )
  1344. {
  1345. echo json_encode( array('code' => 1) );
  1346. die();
  1347. }
  1348. $head_id = $community_info['id'];
  1349. $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve');
  1350. if( empty($open_community_head_leve) )
  1351. {
  1352. $open_community_head_leve = 0;
  1353. }
  1354. //总收入 wait_money
  1355. //lionfish_community_head_commiss_order
  1356. /**总收入 0 1 **/
  1357. $total_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=1" )->sum('money');
  1358. if( empty($total_money) )
  1359. {
  1360. $total_money = 0;
  1361. }
  1362. //tuijian commiss
  1363. //待确认
  1364. $tixian_wait_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=0" )->sum('money');
  1365. if( empty($tixian_wait_money) )
  1366. {
  1367. $tixian_wait_money = 0;
  1368. }
  1369. //已确认
  1370. $tixian_success_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=1" )->sum('money');
  1371. if( empty($tixian_success_money) )
  1372. {
  1373. $tixian_success_money = 0;
  1374. }
  1375. //下级团长数量
  1376. $level_count1 = 0;
  1377. $level_count2 = 0;
  1378. $level_count3 = 0;
  1379. $level_count1 = M('lionfish_community_head')->where( array('agent_id' => $head_id ) )->count();
  1380. if( empty($level_count1) || $level_count1 == 0 )
  1381. {
  1382. $level_count1 = 0;
  1383. }else{
  1384. $level_sql2 =" select count(1) as count from ".C('DB_PREFIX').
  1385. "lionfish_community_head where
  1386. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1387. where agent_id ={$head_id} ) ";
  1388. $level_count2_arr = M()->query($level_sql2);
  1389. $level_count2 = $level_count2_arr[0]['count'];
  1390. if( empty($level_count2) || $level_count2 == 0 )
  1391. {
  1392. $level_count2 = 0;
  1393. }else{
  1394. $level_sqllist2 =" select id from ".C('DB_PREFIX').
  1395. "lionfish_community_head where
  1396. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1397. where agent_id ={$head_id} ) ";
  1398. $level_list2 = M()->query($level_sqllist2);
  1399. if( !empty($level_list2) )
  1400. {
  1401. $level_arr2 = array();
  1402. foreach( $level_list2 as $vvv )
  1403. {
  1404. $level_arr2[] = $vvv['id'];
  1405. }
  1406. $level_sql3 =" select count(1) as count from ".C('DB_PREFIX').
  1407. "lionfish_community_head where agent_id in (".implode(',',$level_arr2).") ";
  1408. $level_count3_arr = M()->query( $level_sql3 );
  1409. $level_count3 = $level_count3_arr[0]['count'];
  1410. if( empty($level_count3) || $level_count3 == 0 )
  1411. {
  1412. $level_count3 = 0;
  1413. }
  1414. }
  1415. }
  1416. }
  1417. $need_data = array();
  1418. $need_data['open_community_head_leve'] = $open_community_head_leve;
  1419. $need_data['total_money'] = $total_money;
  1420. $need_data['wait_money'] = sprintf("%.2f",$tixian_wait_money);
  1421. $need_data['success_money'] = sprintf("%.2f",$tixian_success_money);
  1422. $need_data['level_count1'] = $level_count1;
  1423. $need_data['level_count2'] = $level_count1 + $level_count2 ;
  1424. $need_data['level_count3'] = $level_count1 + $level_count2 + $level_count3;
  1425. echo json_encode( array('code' => 0, 'data' => $need_data ) );
  1426. die();
  1427. }
  1428. /**
  1429. 获取团长分销明细
  1430. **/
  1431. public function get_head_distribute_order()
  1432. {
  1433. $gpc = I('request.');
  1434. $_GPC = I('request.');
  1435. $token = $gpc['token'];
  1436. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1437. $member_id = $weprogram_token['member_id'];
  1438. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  1439. if( empty($member_info) )
  1440. {
  1441. echo json_encode( array('code' => 1) );
  1442. die();
  1443. }
  1444. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1445. if( empty($community_info) || $community_info['state'] != 1 )
  1446. {
  1447. echo json_encode( array('code' => 1) );
  1448. die();
  1449. }
  1450. $head_id = $community_info['id'];
  1451. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  1452. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  1453. $offset = ($page - 1)* $size;
  1454. $where = ' and head_id = '.$head_id;
  1455. $type = isset($_GPC['type']) ? $_GPC['type']: '';
  1456. $level = isset($_GPC['level']) ? $_GPC['level']: 0;
  1457. if( empty($type) )
  1458. {
  1459. $where .= " and type in ('commiss','tuijian')";
  1460. }
  1461. if( $level > 0 )
  1462. {
  1463. //level
  1464. $where .= " and level=".$level;
  1465. }
  1466. //commiss
  1467. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head_commiss_order
  1468. where 1 {$where} order by id desc limit {$offset},{$size}";
  1469. $list = M()->query($sql);
  1470. $status_list = M('lionfish_comshop_order_status')->select();
  1471. $status_arr = array();
  1472. foreach($status_list as $vv)
  1473. {
  1474. $status_arr[ $vv['order_status_id'] ] = $vv['name'];
  1475. }
  1476. $need_list = array();
  1477. foreach($list as $key => $val)
  1478. {
  1479. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  1480. $child_head = M('lionfish_community_head')->where( array('id' => $val['child_head_id'] ) )->find();
  1481. $val['child_head_name'] = $child_head['head_name'];
  1482. $val['community_name'] = $child_head['community_name'];
  1483. if( $val['type'] == 'commiss')
  1484. {
  1485. $order_info = M('lionfish_comshop_order')->field('order_num_alias,order_status_id')
  1486. ->where( array('order_id' => $val['order_id'] ) )->find();
  1487. $val['order_num_alias'] = $order_info['order_num_alias'];
  1488. $val['order_status'] = $status_arr[ $order_info['order_status_id'] ];
  1489. }
  1490. $need_list[$key] = $val;
  1491. }
  1492. if( !empty($need_list) )
  1493. {
  1494. echo json_encode( array('code' => 0, 'data' => $need_list) );
  1495. die();
  1496. }else {
  1497. echo json_encode( array('code' => 1) );
  1498. die();
  1499. }
  1500. }
  1501. //end
  1502. public function tixian_community_info()
  1503. {
  1504. $gpc = I('request.');
  1505. $token = $gpc['token'];
  1506. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1507. $member_id = $weprogram_token['member_id'];
  1508. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1509. if( empty($member_info) )
  1510. {
  1511. echo json_encode( array('code' => 1) );
  1512. die();
  1513. }
  1514. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1515. if( empty($community_info) || $community_info['state'] != 1 )
  1516. {
  1517. echo json_encode( array('code' => 1) );
  1518. die();
  1519. }
  1520. $head_id = $community_info['id'];
  1521. $commission_info = D('Seller/Community')->get_head_commission_info($member_id, $head_id);
  1522. $tixian_money = $gpc['tixian_money'];
  1523. $type = isset($gpc['type']) ? $gpc['type'] : 0;//0 沿用原来的逻辑 1余额 2 微信 3 支付宝 4 银行
  1524. $bankname = isset($gpc['bankname']) ? $gpc['bankname'] : ''; //银行名称
  1525. $bankaccount = isset($gpc['bankaccount']) ? $gpc['bankaccount'] : '';//卡号,支付宝账号 使用该字段
  1526. $bankusername = isset($gpc['bankusername']) ? $gpc['bankusername'] : '';//持卡人姓名,微信名称,支付宝名称, 使用该字段
  1527. $service_charge = D('Home/Front')->get_config_by_name('community_tixian_fee');
  1528. if($commission_info['money'] >= $tixian_money )
  1529. {
  1530. $data = array();
  1531. $data['member_id'] = $member_id;
  1532. $data['head_id'] = $head_id;
  1533. $data['money'] = floatval($tixian_money);
  1534. $data['state'] = 0;
  1535. $data['type'] = $type;
  1536. $data['bankname'] = $bankname;
  1537. $data['bankaccount'] = $bankaccount;
  1538. $data['bankusername'] = $bankusername;
  1539. $data['service_charge'] = round( ($tixian_money * $service_charge) /100,2);
  1540. $data['shentime'] = 0;
  1541. $data['addtime'] = time();
  1542. M('lionfish_community_head_tixian_order')->add($data);
  1543. M()->execute("update ".C('DB_PREFIX')."lionfish_community_head_commiss set money=money - {$tixian_money},dongmoney=dongmoney+{$tixian_money}
  1544. where head_id={$head_id} ");
  1545. echo json_encode( array('code' => 0) );
  1546. die();
  1547. }else{
  1548. echo json_encode( array('code'=>1) );
  1549. die();
  1550. }
  1551. }
  1552. public function sub_community_head()
  1553. {
  1554. $gpc = I('request.');
  1555. $token = $gpc['token'];
  1556. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1557. $member_id = $weprogram_token['member_id'];
  1558. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1559. if( empty($member_info) )
  1560. {
  1561. echo json_encode( array('code' => 1) );
  1562. die();
  1563. }
  1564. $province_name = $gpc['province_name'];
  1565. $city_name = $gpc['city_name'];
  1566. $area_name = $gpc['area_name'];
  1567. $country_name = $gpc['country_name'];
  1568. $lon_lat = $gpc['lon_lat'];
  1569. $lon_lat_arr = explode(',', $lon_lat);
  1570. $wechat = $gpc['wechat'];
  1571. $province_info = D('Home/Front')->get_area_ninfo_by_name($province_name);
  1572. $province_id = $province_info['id'];
  1573. $city_info = D('Home/Front')->get_area_ninfo_by_name($city_name);
  1574. $city_id = $city_info['id'];
  1575. $area_info = D('Home/Front')->get_area_ninfo_by_name($area_name);
  1576. $area_id = $area_info['id'];
  1577. $country_info = D('Home/Front')->get_area_ninfo_by_name($country_name);
  1578. $country_id = $country_info['id'];
  1579. $addr_detail = $gpc['addr_detail'];
  1580. $community_name = $gpc['community_name'];
  1581. $mobile = $gpc['mobile'];
  1582. $head_name = $gpc['head_name'];
  1583. $community_id = isset($gpc['community_id']) && intval($gpc['community_id']) > 0 ? $gpc['community_id'] : 0;
  1584. $data = array();
  1585. $data['member_id'] = $member_id;
  1586. $data['community_name'] = $community_name;
  1587. $data['head_name'] = $head_name;
  1588. $data['head_mobile'] = $mobile;
  1589. $data['province_id'] = $province_id;
  1590. $data['city_id'] = $city_id;
  1591. $data['country_id'] = $country_id;
  1592. $data['area_id'] = $area_id;
  1593. $data['address'] = $addr_detail;
  1594. $data['lon'] = $lon_lat_arr[0];
  1595. $data['lat'] = $lon_lat_arr[1];
  1596. $data['state'] = 0;
  1597. $data['apptime'] = time();
  1598. $data['addtime'] = time();
  1599. $data['wechat'] = $wechat;
  1600. $head_info = D('Home/Front')->get_member_community_info($member_id);
  1601. $parent_head_id = 0;
  1602. if( $member_info['share_id'] > 0 )
  1603. {
  1604. $parent_head_info = D('Home/Front')->get_member_community_info($member_info['share_id']);
  1605. if( !empty($parent_head_info) )
  1606. {
  1607. $parent_head_id = $parent_head_info['id'];
  1608. }
  1609. }
  1610. $data['agent_id'] = $parent_head_id;
  1611. if( $community_id > 0 )
  1612. {
  1613. $data['agent_id'] = $community_id;
  1614. }
  1615. if( empty($head_info) )
  1616. {
  1617. $head_id = M('lionfish_community_head')->add($data);
  1618. }else{
  1619. unset($data['uniacid']);
  1620. unset($data['addtime']);
  1621. M('lionfish_community_head')->where( array('id' => $head_info['id']) )->save($data);
  1622. $head_id = $head_info['id'];
  1623. }
  1624. $head_commiss_info = M('lionfish_community_head_commiss')->where( array('member_id' =>$member_id,'head_id' => $head_id ) )->find();
  1625. if( empty($head_commiss_info) )
  1626. {
  1627. $datas = array();
  1628. $datas['member_id'] = $member_id;
  1629. $datas['head_id'] = $head_id;
  1630. $datas['money'] = 0;
  1631. $datas['dongmoney'] = 0;
  1632. $datas['getmoney'] = 0;
  1633. $datas['bankname'] = '';
  1634. $datas['bankaccount'] = '';
  1635. $datas['bankusername'] = '';
  1636. $datas['share_avatar'] = '';
  1637. $datas['share_wxcode'] = '';
  1638. $datas['share_title'] = '';
  1639. $datas['share_desc'] = '';
  1640. M('lionfish_community_head_commiss')->add( $datas );
  1641. }
  1642. echo json_encode( array('code' => 0) );
  1643. die();
  1644. }
  1645. /**
  1646. * 获取城市列表
  1647. */
  1648. public function get_city_list()
  1649. {
  1650. $gpc = I('request.');
  1651. $token = $gpc['token'];
  1652. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1653. $member_id = $weprogram_token['member_id'];
  1654. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1655. if( empty($member_info) )
  1656. {
  1657. //echo json_encode( array('code' => 1) );
  1658. //die();
  1659. }
  1660. $city_ids_Arr = M('lionfish_community_head')->field('city_id')->order('city_id asc')->select();
  1661. $city_ids = array();
  1662. foreach ($city_ids_Arr as $k => $val) {
  1663. $city_ids[] = $val['city_id'];
  1664. }
  1665. $city_ids_str = implode(',', $city_ids);
  1666. $city_list = M('lionfish_comshop_area')->where( array('id' => array('in', $city_ids_str) ) )->select();
  1667. // {
  1668. // "districtCode": "152900",
  1669. // "districtLevel": "CITY",
  1670. // "parentDistrictCode": "150000",
  1671. // "districtName": "阿拉善盟",
  1672. // "firstLetter": "A",
  1673. // "serviceStatus": "N"
  1674. // }
  1675. $city_arr = array();
  1676. foreach ($city_list as $key => $value) {
  1677. $city_arr[$key]["city_id"] = $value["id"];
  1678. $city_arr[$key]["districtCode"] = $value["code"];
  1679. $city_arr[$key]["districtLevel"] = "CITY";
  1680. $city_arr[$key]["parentDistrictCode"] = $value["code"];
  1681. $city_arr[$key]["districtName"] = $value["name"];
  1682. $city_arr[$key]["firstLetter"] = $this->getFirstCharter($value["name"]);
  1683. $city_arr[$key]["serviceStatus"] = "N";
  1684. }
  1685. echo json_encode( array('code' => 0, 'data' => $city_arr) );
  1686. die();
  1687. }
  1688. /**
  1689. * 获取首字母
  1690. * @param [type] $str [description]
  1691. * @return [type] [description]
  1692. */
  1693. function getFirstCharter($str)
  1694. {
  1695. if (empty($str)) {
  1696. return '';
  1697. }
  1698. $fchar = ord($str{0});
  1699. if ($fchar >= ord('A') && $fchar <= ord('z'))
  1700. return strtoupper($str{0});
  1701. $s1 = iconv('UTF-8', 'gb2312', $str);
  1702. $s2 = iconv('gb2312', 'UTF-8', $s1);
  1703. $s = $s2 == $str ? $s1 : $str;
  1704. $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
  1705. if ($asc >= -20319 && $asc <= -20284)
  1706. return 'A';
  1707. if ($asc >= -20283 && $asc <= -19776)
  1708. return 'B';
  1709. if ($asc >= -19775 && $asc <= -19219)
  1710. return 'C';
  1711. if ($asc >= -19218 && $asc <= -18711)
  1712. return 'D';
  1713. if ($asc >= -18710 && $asc <= -18527)
  1714. return 'E';
  1715. if ($asc >= -18526 && $asc <= -18240)
  1716. return 'F';
  1717. if ($asc >= -18239 && $asc <= -17923)
  1718. return 'G';
  1719. if ($asc >= -17922 && $asc <= -17418)
  1720. return 'H';
  1721. if ($asc >= -17417 && $asc <= -16475)
  1722. return 'J';
  1723. if ($asc >= -16474 && $asc <= -16213)
  1724. return 'K';
  1725. if ($asc >= -16212 && $asc <= -15641)
  1726. return 'L';
  1727. if ($asc >= -15640 && $asc <= -15166)
  1728. return 'M';
  1729. if ($asc >= -15165 && $asc <= -14923)
  1730. return 'N';
  1731. if ($asc >= -14922 && $asc <= -14915)
  1732. return 'O';
  1733. if ($asc >= -14914 && $asc <= -14631)
  1734. return 'P';
  1735. if ($asc >= -14630 && $asc <= -14150)
  1736. return 'Q';
  1737. if ($asc >= -14149 && $asc <= -14091)
  1738. return 'R';
  1739. if ($asc >= -14090 && $asc <= -13319)
  1740. return 'S';
  1741. if ($asc >= -13318 && $asc <= -12839)
  1742. return 'T';
  1743. if ($asc >= -12838 && $asc <= -12557)
  1744. return 'W';
  1745. if ($asc >= -12556 && $asc <= -11848)
  1746. return 'X';
  1747. if ($asc >= -11847 && $asc <= -11056)
  1748. return 'Y';
  1749. if ($asc >= -11055 && $asc <= -10247)
  1750. return 'Z';
  1751. return null;
  1752. }
  1753. /**
  1754. * 获取申请页面
  1755. */
  1756. public function get_apply_page()
  1757. {
  1758. $info = M('lionfish_comshop_config')->field( 'value' )->where( array('name' => 'communityhead_apply_page') )->find();
  1759. if(!empty($info['value'])){
  1760. echo json_encode( array('code' => 0, 'data' => htmlspecialchars_decode(htmlspecialchars_decode($info['value']))) );
  1761. die();
  1762. }else{
  1763. echo json_encode( array('code' => 1 ));
  1764. die();
  1765. }
  1766. }
  1767. public function check_head_subscriptapply()
  1768. {
  1769. $_GPC = I('request.');
  1770. $token = $_GPC['token'];
  1771. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1772. $member_id = $weprogram_token['member_id'];
  1773. $is_need_subscript = 0;
  1774. $need_subscript_template = array();
  1775. //'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
  1776. $apply_community_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'apply_community' ) )->find();
  1777. if( empty($apply_community_info) )
  1778. {
  1779. $weprogram_subtemplate_apply_community = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_community');
  1780. if( !empty($weprogram_subtemplate_apply_community) )
  1781. {
  1782. $need_subscript_template['apply_community'] = $weprogram_subtemplate_apply_community;
  1783. }
  1784. }
  1785. $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'apply_tixian' ) )->find();
  1786. if( empty($apply_tixian_info) )
  1787. {
  1788. $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  1789. if( !empty($weprogram_subtemplate_apply_tixian) )
  1790. {
  1791. $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
  1792. }
  1793. }
  1794. if( !empty($need_subscript_template) )
  1795. {
  1796. $is_need_subscript = 1;
  1797. }
  1798. echo json_encode( array('code' => 0, 'is_need_subscript' => $is_need_subscript,'need_subscript_template' => $need_subscript_template ) );
  1799. die();
  1800. }
  1801. //----------begin ----------------
  1802. /**
  1803. * 团长设置页面团长资料
  1804. */
  1805. public function get_head_info()
  1806. {
  1807. $_GPC = I('request.');
  1808. $token = $_GPC['token'];
  1809. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1810. $member_id = $weprogram_token['member_id'];
  1811. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1812. if( empty($member_info) )
  1813. {
  1814. echo json_encode( array('code' => 1) );
  1815. die();
  1816. }
  1817. $id = $_GPC['id'];
  1818. if($id > 0)
  1819. {
  1820. $item = M('lionfish_community_head')->where( array('id' => $id ) )->find();
  1821. $item['province_name'] = D('Seller/Area')->get_area_info($item['province_id']);
  1822. $item['city_name'] = D('Seller/Area')->get_area_info($item['city_id']);
  1823. $item['area_name'] = D('Seller/Area')->get_area_info($item['area_id']);
  1824. $item['country_name'] = D('Seller/Area')->get_area_info($item['country_id']);
  1825. if( $item['member_id'] > 0)
  1826. {
  1827. $head_commiss_info = M('lionfish_community_head_commiss')->where( array('head_id' => $item['id'],'member_id' =>$item['member_id'] ) )->find();
  1828. if( !empty($head_commiss_info) )
  1829. {
  1830. $item['bankname'] = $head_commiss_info['bankname'];
  1831. $item['bankaccount'] = $head_commiss_info['bankaccount'];
  1832. $item['bankusername'] = $head_commiss_info['bankusername'];
  1833. $item['share_wxcode'] = tomedia($head_commiss_info['share_wxcode']);
  1834. }
  1835. }
  1836. $item['member_info'] = $member_info;
  1837. $item['rest'] = D('Seller/Communityhead')->is_community_rest($id);
  1838. $item['re_id'] = sprintf("%05d", $item['id']);
  1839. $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
  1840. $close_community_reset_btn = D('Home/Front')->get_config_by_name('close_community_reset_btn');
  1841. if(empty($delivery_type_tuanz))
  1842. {
  1843. $delivery_type_tuanz = 2;
  1844. }
  1845. $item['delivery_type_tuanz'] = $delivery_type_tuanz;
  1846. $item['close_reset_btn'] = $close_community_reset_btn;
  1847. if(!empty($item)){
  1848. echo json_encode( array('code' => 0, 'data' => $item) );
  1849. die();
  1850. }else{
  1851. // 无数据
  1852. echo json_encode( array('code' => 2 ));
  1853. die();
  1854. }
  1855. }
  1856. }
  1857. /**
  1858. * 团长设置休息状态
  1859. */
  1860. public function set_head_rest()
  1861. {
  1862. $_GPC = I('request.');
  1863. $token = $_GPC['token'];
  1864. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1865. $member_id = $weprogram_token['member_id'];
  1866. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1867. if( empty($member_info) )
  1868. {
  1869. echo json_encode( array('code' => 1) );
  1870. die();
  1871. }
  1872. $head_id = $_GPC['id'];
  1873. $rest = $_GPC['rest'];
  1874. if($head_id > 0){
  1875. $result = M('lionfish_community_head')->where( array('id' => $head_id) )->save( array('rest' => $rest) );
  1876. if(!empty($result)){
  1877. echo json_encode( array('code' => 0, 'data' => '修改成功'));
  1878. die();
  1879. }else{
  1880. echo json_encode( array('code' => 2, 'data' => '修改失败'));
  1881. die();
  1882. }
  1883. }else{
  1884. // id不存在
  1885. echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
  1886. die();
  1887. }
  1888. }
  1889. /**
  1890. * 团长信息修改
  1891. */
  1892. public function modify_head_info()
  1893. {
  1894. $_GPC = I('request.');
  1895. $token = $_GPC['token'];
  1896. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1897. $member_id = $weprogram_token['member_id'];
  1898. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1899. if( empty($member_info) )
  1900. {
  1901. echo json_encode( array('code' => 1) );
  1902. die();
  1903. }
  1904. $head_id = isset($_GPC['id']) ? $_GPC['id'] : 0;
  1905. $data = array();
  1906. $data['head_name'] = $_GPC['head_name'];
  1907. $data['head_mobile'] = $_GPC['head_mobile'];
  1908. $data['is_modify_shipping_method'] = $_GPC['is_modify_shipping_method'];//是否自定义配送开关。0跟随系统,1开启,2关闭
  1909. $data['is_modify_shipping_fare'] = $_GPC['is_modify_shipping_fare'];//是否自定义配送费,0跟随系统,1自定义
  1910. $data['shipping_fare'] = $_GPC['shipping_fare'];// 自定义配送费
  1911. if($head_id > 0){
  1912. $rs = M('lionfish_community_head')->where( array('id' => $head_id, 'member_id' => $member_id) )->save( $data );
  1913. $commiss_data = array();
  1914. $commiss_data['share_wxcode'] = $_GPC['share_wxcode'];
  1915. if($commiss_data['share_wxcode']){
  1916. $rs = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id, 'member_id' => $member_id) )->save( $commiss_data );
  1917. }
  1918. if(!empty($rs)){
  1919. echo json_encode( array('code' => 0, 'data' => '修改成功'));
  1920. die();
  1921. }else{
  1922. echo json_encode( array('code' => 2, 'data' => '修改失败'));
  1923. die();
  1924. }
  1925. }else{
  1926. // id不存在
  1927. echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
  1928. die();
  1929. }
  1930. }
  1931. /**
  1932. * 团长信息修改
  1933. */
  1934. public function modify_head_commiss()
  1935. {
  1936. $_GPC = I('request.');
  1937. $token = $_GPC['token'];
  1938. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1939. $member_id = $weprogram_token['member_id'];
  1940. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1941. if( empty($member_info) )
  1942. {
  1943. echo json_encode( array('code' => 1) );
  1944. die();
  1945. }
  1946. $head_id = isset($_GPC['id']) ? $_GPC['id'] : 0;
  1947. $data = array();
  1948. $data['bankname'] = $_GPC['bankname'];
  1949. $data['bankaccount'] = $_GPC['bankaccount'];
  1950. $data['bankusername'] = $_GPC['bankusername'];
  1951. // $data['address'] = $_GPC['address'];
  1952. // $data['lon'] = $_GPC['lon'];
  1953. // $data['lat'] = $_GPC['lat'];
  1954. // $data['state'] = $_GPC['state'];
  1955. if($head_id > 0){
  1956. $rs = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id, 'member_id' => $member_id) )->save( $data );
  1957. if(!empty($rs)){
  1958. echo json_encode( array('code' => 0, 'data' => '修改成功'));
  1959. die();
  1960. }else{
  1961. echo json_encode( array('code' => 2, 'data' => '修改失败'));
  1962. die();
  1963. }
  1964. }else{
  1965. // id不存在
  1966. echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
  1967. die();
  1968. }
  1969. }
  1970. public function community_index_shareqrcode()
  1971. {
  1972. $_GPC = I('request.');
  1973. $token = $_GPC['token'];
  1974. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1975. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1976. {
  1977. $member_id = 0;
  1978. }else{
  1979. $member_id = $weprogram_token['member_id'];
  1980. }
  1981. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1982. if( empty($member_info) )
  1983. {
  1984. echo json_encode( array('code' => 1) );
  1985. die();
  1986. }
  1987. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1988. if( empty($community_info) || $community_info['state'] != 1 )
  1989. {
  1990. echo json_encode( array('code' => 1) );
  1991. die();
  1992. }
  1993. $community_id = $community_info['id'];
  1994. $community_index_shareqrcode_json = D('Home/Front')->get_config_by_name('community_index_shareqrcode_'.$community_id );
  1995. $community_index_shareqrcode_arr = unserialize($community_index_shareqrcode_json);
  1996. $load_new = false;
  1997. if( empty($community_index_shareqrcode_arr) )
  1998. {
  1999. $load_new = true;
  2000. }else {
  2001. if( $community_index_shareqrcode_arr['endtime'] < time() )
  2002. {
  2003. $load_new = true;
  2004. }
  2005. }
  2006. if( $load_new || true )
  2007. {
  2008. $goods_model = D('Home/Pingoods');
  2009. $qrcode_image = $goods_model->_get_index_wxqrcode($member_id,$community_id,'jpg');
  2010. $data = array();
  2011. $data['image_path'] = '/'.$qrcode_image;
  2012. $ed_time = time() + 300;
  2013. $js_arr = array('endtime' => $ed_time,'image_path' => $data['image_path'] );
  2014. $cd_key = 'community_index_shareqrcode_'.$community_id;
  2015. D('Seller/Config')->update( array( $cd_key => serialize($js_arr) ) );
  2016. }else{
  2017. $data = array();
  2018. $data['image_path'] ='/'.$community_index_shareqrcode_arr['image_path'];
  2019. }
  2020. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  2021. $data['image_path'] = $shop_domain.$data['image_path'];
  2022. $result = array('code' => 0, 'qrcode' => $data['image_path'] );
  2023. echo json_encode($result);
  2024. die();
  2025. }
  2026. /**
  2027. * 团长排行榜
  2028. */
  2029. public function community_ranking_list(){
  2030. $_GPC = I('request.');
  2031. $token = $_GPC['token'];
  2032. $type = $_GPC['type'];
  2033. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2034. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2035. {
  2036. $member_id = 0;
  2037. }else{
  2038. $member_id = $weprogram_token['member_id'];
  2039. }
  2040. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  2041. if( empty($member_info) )
  2042. {
  2043. echo json_encode( array('code' => 1, 'mgs'=> '请登录') );
  2044. die();
  2045. }
  2046. $community_info = D('Home/Front')->get_member_community_info($member_id);
  2047. if( empty($community_info) || $community_info['state'] != 1 )
  2048. {
  2049. echo json_encode( array('code' => 1, 'mgs'=> '您不是团长,无法查看') );
  2050. die();
  2051. }
  2052. $begin_time = 0;
  2053. $end_time = 0;
  2054. if($type == 1){//今日
  2055. $begin_time = strtotime(date('Y-m-d'.'00:00:00',time()));
  2056. $end_time = strtotime(date('Y-m-d'.'00:00:00',time()+3600*24));
  2057. }else if($type == 2){//昨日
  2058. $begin_time = strtotime(date('Y-m-d'.'00:00:00',time()-3600*24));
  2059. $end_time = strtotime(date('Y-m-d'.'00:00:00',time()));
  2060. }else if($type == 3){//上周
  2061. $begin_time = strtotime(date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'))));
  2062. $end_time = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'))));
  2063. }else if($type == 4){//上月
  2064. //上月开始时间
  2065. $begin_time = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))));
  2066. //上月结束时间
  2067. $end_time = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))));
  2068. }
  2069. $list = array();
  2070. $sql = " select * from ( "
  2071. . " select co.head_id,count(distinct(co.order_id)) as order_count, "
  2072. . " sum(co.money) as money "
  2073. . " from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co "
  2074. . " left join ".C('DB_PREFIX')."lionfish_comshop_order as o "
  2075. . " on co.order_id = o.order_id "
  2076. . " left join ".C('DB_PREFIX')."lionfish_community_head as h "
  2077. . " on co.head_id = h.id "
  2078. . " where co.addtime >= ".$begin_time." and co.addtime <= ".$end_time
  2079. . " and o.order_status_id not in (3,5,7,12) and co.state != 2 and h.state = 1 and h.enable = 1 "
  2080. . " group by co.head_id) t "
  2081. . " order by money desc "
  2082. . " limit 20 ";
  2083. //echo $sql;
  2084. $list = M()->query($sql);
  2085. foreach($list as $k=>$v){
  2086. $community_head = M('lionfish_community_head')->where( array('id' => $v['head_id']) )->find();
  2087. $list[$k]['community_name'] = $community_head['community_name'];
  2088. $member_info = M('lionfish_comshop_member')->field('avatar')->where( array('member_id' => $community_head['member_id']) )->find();
  2089. $list[$k]['avatar'] = $member_info['avatar'];
  2090. }
  2091. $is_show_community_ranking = D('Home/Front')->get_config_by_name('is_show_community_ranking');
  2092. //是否显示团长排行, 0不显示,1显示
  2093. $is_show_community_ranking = empty($is_show_community_ranking) ? 0 : $is_show_community_ranking;
  2094. echo json_encode(array('code' => 0,'data'=>$list , 'is_show_community_ranking' => $is_show_community_ranking ));
  2095. die();
  2096. }
  2097. //----------end----------------------
  2098. }