CommunityController.class.php 74 KB

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