DistributionController.class.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  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 Seller\Controller;
  15. class DistributionController extends CommonController {
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function distributionpostal()
  20. {
  21. if (IS_POST) {
  22. $data = I('request.data');
  23. D('Seller/Config')->update($data);
  24. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  25. }
  26. $data = D('Seller/Config')->get_all_config();
  27. $this->data = $data;
  28. $this->display();
  29. }
  30. public function changename()
  31. {
  32. $_GPC = I('request.');
  33. $id = intval($_GPC['id']);
  34. //ids
  35. if (empty($id)) {
  36. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  37. }
  38. if (empty($id)) {
  39. show_json(0, array('message' => '参数错误'));
  40. }
  41. $type = trim($_GPC['type']);
  42. $value = trim($_GPC['value']);
  43. $items = M('lionfish_comshop_member_tixian_order')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  44. foreach ($items as $item ) {
  45. M('lionfish_comshop_member_tixian_order')->where( array('id' => $item['id']) )->save( array('bankusername' => $value) );
  46. }
  47. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  48. }
  49. public function clear_user_member_qrcode()
  50. {
  51. M('lionfish_comshop_member')->where( "member_id > 0" )->save( array('wepro_qrcode' => '') );
  52. echo json_encode( array('code' => 0) );
  53. die();
  54. }
  55. public function config()
  56. {
  57. if (IS_POST) {
  58. $data = I('request.data');
  59. if($data['commiss_sharemember_need'] == 1){
  60. $commiss_share_member_update = intval($data['commiss_share_member_update']);
  61. if($commiss_share_member_update < 1){
  62. show_json(0, array('message' => '分享人数最少1人'));
  63. }
  64. }
  65. D('Seller/Config')->update($data);
  66. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  67. }
  68. $data = D('Seller/Config')->get_all_config();
  69. $this->data = $data;
  70. $this->display();
  71. }
  72. public function qrcodeconfig()
  73. {
  74. if (IS_POST) {
  75. $_GPC = I('request.');
  76. $data = array();
  77. $data['distribution_avatar_left'] = $_GPC['avatar_left'];
  78. $data['distribution_avatar_top'] = $_GPC['avatar_top'];
  79. $data['distribution_qrcodes_left'] = $_GPC['qrcodes_left'];
  80. $data['distribution_qrcodes_top'] = $_GPC['qrcodes_top'];
  81. $data['distribution_username_left'] = $_GPC['username_left'];
  82. $data['distribution_username_top'] = $_GPC['username_top'];
  83. $data['distribution_img_src'] = $_GPC['img_src'];
  84. $data['commiss_avatar_rgb'] = $_GPC['commiss_avatar_rgb'];
  85. $data['commiss_nickname_rgb'] = $_GPC['commiss_nickname_rgb'];
  86. D('Seller/Config')->update($data);
  87. M('lionfish_comshop_member')->where( "1" )->save( array('commiss_qrcode' => '') );
  88. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  89. }
  90. $data = D('Seller/Config')->get_all_config();
  91. $this->data = $data;
  92. $this->display();
  93. }
  94. public function addForm()
  95. {
  96. if (IS_POST) {
  97. $data = I('request.data');
  98. D('Seller/Config')->update(array('commiss_diy_form' => serialize( $data ) ));
  99. show_json(0, array('url' => $_SERVER['HTTP_REFERER']));
  100. }
  101. $data = M('lionfish_comshop_config')->where( array('name' => 'commiss_diy_form') )->find();
  102. $form_data = array();
  103. if( !empty($data) )
  104. {
  105. $form_data = unserialize( htmlspecialchars_decode( $data['value'] ));
  106. }
  107. $this->form_data = $form_data;
  108. include $this->display();
  109. }
  110. public function withdraw_config()
  111. {
  112. if (IS_POST) {
  113. $data = I('request.data');
  114. $data['commiss_tixianway_yuer'] = isset($data['commiss_tixianway_yuer']) ? $data['commiss_tixianway_yuer']:1;
  115. $data['commiss_tixianway_weixin'] = isset($data['commiss_tixianway_weixin']) ? $data['commiss_tixianway_weixin']:1;
  116. $data['commiss_tixianway_alipay'] = isset($data['commiss_tixianway_alipay']) ? $data['commiss_tixianway_alipay']:1;
  117. $data['commiss_tixianway_bank'] = isset($data['commiss_tixianway_bank']) ? $data['commiss_tixianway_bank']:1;
  118. $data['commiss_tixian_publish'] = isset($data['commiss_tixian_publish']) ? $data['commiss_tixian_publish']:'';
  119. D('Seller/Config')->update($data);
  120. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  121. }
  122. $data = D('Seller/Config')->get_all_config();
  123. $this->data = $data;
  124. $this->display();
  125. }
  126. public function distributionorder()
  127. {
  128. $time = I('request.time');
  129. $_GPC = I('request.');
  130. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  131. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  132. $this->searchfield = I('request.searchfield','');
  133. $this->keyword = I('request.keyword','');
  134. $this->searchtime = I('request.searchtime','');
  135. $this->delivery = I('request.delivery','');
  136. $this->starttime = $starttime;
  137. $this->endtime = $endtime;
  138. $this->time = $time;
  139. $order_status_id = I('request.order_status_id',0);
  140. $starttime = isset($_GPC['time']['start']) ? strtotime($_GPC['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  141. $endtime = isset($_GPC['time']['end']) ? strtotime($_GPC['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  142. $order_status_arr = D('Seller/Order')->get_order_status_name();
  143. $this->order_status_arr = $order_status_arr;
  144. $_GPC['is_fenxiao'] = 1;//分销订单
  145. $this->_GPC = $_GPC;
  146. $this->is_fenxiao = 1;
  147. $cur_controller = 'distribution/distributionorder';
  148. $need_data = D('Seller/Order')->load_order_list(0,1);
  149. $total = $need_data['total'];
  150. $total_money = $need_data['total_money'];
  151. $list = $need_data['list'];
  152. $pager = $need_data['pager'];
  153. $all_count = $need_data['all_count'];
  154. $count_status_1 = $need_data['count_status_1'];
  155. $count_status_3 = $need_data['count_status_3'];
  156. $count_status_4 = $need_data['count_status_4'];
  157. $count_status_5 = $need_data['count_status_5'];
  158. $count_status_7 = $need_data['count_status_7'];
  159. $count_status_11 = $need_data['count_status_11'];
  160. $count_status_14 = $need_data['count_status_14'];
  161. $this->cur_controller = $cur_controller;
  162. $this->total = $total;
  163. $this->total_money = $total_money;
  164. $this->list = $list;
  165. $this->pager = $pager;
  166. $this->all_count = $all_count;
  167. $this->count_status_1 = $count_status_1;
  168. $this->count_status_3 = $count_status_3;
  169. $this->count_status_4 = $count_status_4;
  170. $this->count_status_5 = $count_status_5;
  171. $this->count_status_7 = $count_status_7;
  172. $this->count_status_11 = $count_status_11;
  173. $this->count_status_14 = $count_status_14;
  174. $this->order_status_id = $order_status_id;
  175. $this->is_community = I('request.is_community', 0);
  176. $this->headid = I('request.headid', 0);
  177. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  178. if( empty($open_feier_print) )
  179. {
  180. $open_feier_print = 0;
  181. }
  182. $this->open_feier_print = $open_feier_print;
  183. $this->display('Order/index');
  184. }
  185. public function communityorder()
  186. {
  187. $_GPC = I('request.');
  188. $member_id = $_GPC['member_id'];
  189. $pindex = max(1, intval($_GPC['page']));
  190. $psize = 20;
  191. $where = " and co.member_id = {$member_id} ";
  192. $starttime = strtotime( date('Y-m-d')." 00:00:00" );
  193. $endtime = $starttime + 86400;
  194. if( isset($_GPC['searchtime']) && $_GPC['searchtime'] == 'create_time' )
  195. {
  196. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  197. $starttime = strtotime($_GPC['time']['start']);
  198. $endtime = strtotime($_GPC['time']['end']);
  199. $where .= ' AND co.addtime >= '.$starttime.' AND co.addtime <= '.$endtime.' ';
  200. }
  201. }
  202. $this->member_id = $member_id;
  203. $this->starttime = $starttime;
  204. $this->endtime = $endtime;
  205. if ($_GPC['order_status'] != '') {
  206. $where .= ' and co.state=' . intval($_GPC['order_status']);
  207. }
  208. $sql = "select co.order_id,co.state,co.money,co.level,co.addtime ,og.total,og.name,og.total
  209. from ".C('DB_PREFIX')."lionfish_comshop_member_commiss_order as co ,
  210. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  211. where co.order_goods_id = og.order_goods_id {$where}
  212. order by co.id desc ".' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  213. $list = M()->query($sql);
  214. if( !empty($list) )
  215. {
  216. foreach($list as $key => $val)
  217. {
  218. $val['total'] = sprintf("%.2f",$val['total']);
  219. $val['money'] = sprintf("%.2f",$val['money']);
  220. $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
  221. $order_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id'] ) )->find();
  222. $val['order_num_alias'] = $order_info['order_num_alias'];
  223. $list[$key] = $val;
  224. }
  225. }
  226. $sql_count = "select count(1) as count
  227. from ".C('DB_PREFIX')."lionfish_comshop_member_commiss_order as co ,
  228. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  229. where co.order_goods_id = og.order_goods_id {$where} ";
  230. $total_arr = M()->query($sql_count);
  231. $total = $total_arr[0]['count'];
  232. if ($_GPC['export'] == '1') {
  233. $export_sql = "select co.order_id,co.state,co.money,co.level,co.addtime ,og.total,og.name,og.total
  234. from ".C('DB_PREFIX')."lionfish_comshop_member_commiss_order as co ,
  235. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  236. where co.order_goods_id = og.order_goods_id {$where}
  237. order by co.id desc ";
  238. $export_list = M()->query($export_sql);
  239. if( !empty($export_list) )
  240. {
  241. foreach($export_list as $key => $val)
  242. {
  243. $val['total'] = sprintf("%.2f",$val['total']);
  244. $val['money'] = sprintf("%.2f",$val['money']);
  245. $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
  246. $order_info= M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id'] ) )->find();
  247. $val['order_num_alias'] = $order_info['order_num_alias'];
  248. $export_list[$key] = $val;
  249. }
  250. }
  251. foreach($export_list as $key =>&$row)
  252. {
  253. $row['order_num_alias'] = "\t".$row['order_num_alias'];
  254. $row['name'] = $row['name'];
  255. $row['total'] = $row['total'];
  256. $row['money'] = $row['money'];
  257. if($row['state'] == 0)
  258. {
  259. $row['state'] = '待结算';
  260. }else if($row[state] == 1)
  261. {
  262. $row['state'] = '已结算';
  263. }else if($row[state] == 2){
  264. $row['state'] = '订单取消或退款';
  265. }
  266. $row['addtime'] = $row['addtime'];
  267. }
  268. unset($row);
  269. $columns = array(
  270. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 24),
  271. array('title' => '商品标题', 'field' => 'name', 'width' => 24),
  272. array('title' => '订单金额', 'field' => 'total', 'width' => 12),
  273. array('title' => '佣金金额', 'field' => 'money', 'width' => 12),
  274. array('title' => '几级分佣', 'field' => 'level', 'width' => 12),
  275. array('title' => '状态', 'field' => 'state', 'width' => 24),
  276. array('title' => '下单时间', 'field' => 'addtime', 'width' => 24),
  277. );
  278. D('Seller/Excel')->export($export_list, array('title' => '会员分销收益明细-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  279. }
  280. $pager = pagination2($total, $pindex, $psize);
  281. $this->pager = $pager;
  282. $this->list = $list;
  283. $this->_GPC = $_GPC;
  284. $this->display();
  285. }
  286. public function changecommission()
  287. {
  288. $_GPC = I('request.');
  289. $order_id = $_GPC['order_id'];
  290. $order_goods_id = $_GPC['order_goods_id'];
  291. $commiss_level = D('Seller/Front')->get_config_by_name('commiss_level');
  292. $commission_info = D('Home/Commission')->get_order_goods_commission( $order_id, $order_goods_id);
  293. if (empty($commission_info)) {
  294. if (IS_POST) {
  295. show_json(0, array('message' => '未找到订单!'));
  296. }
  297. exit('fail');
  298. }
  299. if (IS_POST) {
  300. $cm1 = $_GPC['cm1'];
  301. if (!is_array($cm1) ) {
  302. show_json(0, array('message' => '未找到修改数据!'));
  303. }
  304. foreach ($cm1 as $id => $money) {
  305. M('lionfish_comshop_member_commiss_order')->where( array('id' => $id) )->save( array('money' => $money) );
  306. }
  307. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  308. }
  309. foreach( $commission_info as $key => $val )
  310. {
  311. $mb_info = M('lionfish_comshop_member')->field('username,avatar')->where( array('member_id' => $val['member_id'] ) )->find();
  312. $val['member_info'] = $mb_info;
  313. $commission_info[$key] = $val;
  314. }
  315. $this->order_id = $order_id;
  316. $this->order_goods_id = $order_goods_id;
  317. $this->commiss_level = $commiss_level;
  318. $this->commission_info = $commission_info;
  319. $this->display();
  320. }
  321. public function level()
  322. {
  323. $data = D('Seller/Config')->get_all_config();
  324. $default = array('id' => 'default', 'levelname' => empty($data['commission_levelname']) ? '默认等级' : $data['commission_levelname'], 'commission1' => $data['commission1'], 'commission2' => $data['commission2'], 'commission3' => $data['commission3']);
  325. $others = M('lionfish_comshop_commission_level')->order('commission1 asc')->select();
  326. $list = array_merge(array($default), $others);
  327. $this->data = $data;
  328. $this->list = $list;
  329. $this->display();
  330. }
  331. public function addlevel()
  332. {
  333. $this->modifylevel();
  334. }
  335. public function editlevel()
  336. {
  337. $this->modifylevel();
  338. }
  339. public function become_agent_check()
  340. {
  341. $_GPC = I('request.');
  342. $member_id = $_GPC['id'];
  343. $state = $_GPC['state'];
  344. $member = M('lionfish_comshop_member')->field('member_id,openid,we_openid,comsiss_state')->where( array('member_id' => $member_id) )->find();
  345. if( $state == 1 )
  346. {
  347. $time = time();
  348. M('lionfish_comshop_member')->where( array('member_id' => $member['member_id']) )->save( array('comsiss_state' => 1,'comsiss_flag' => 1, 'comsiss_time' => $time, 'is_comsiss_admin'=>1) );
  349. //检测是否存在账户,没有就新建
  350. D('Home/Commission')->commission_account($member['member_id']);
  351. //TODO....sendmsg 发送成为分销商的信息
  352. }else{
  353. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('comsiss_state' => 0,'comsiss_flag' => 1, 'comsiss_time' => 0) );
  354. }
  355. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  356. }
  357. public function agent_check()
  358. {
  359. $_GPC = I('request.');
  360. $id = intval($_GPC['id']);
  361. if (empty($id)) {
  362. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  363. }
  364. $comsiss_state = intval($_GPC['comsiss_state']);
  365. $members = M('lionfish_comshop_member')->field('member_id,openid,we_openid,comsiss_state')->where( 'member_id in( ' . $id . ' )' )->select();
  366. $time = time();
  367. foreach ($members as $member) {
  368. if ($member['comsiss_state'] === $comsiss_state) {
  369. continue;
  370. }
  371. if ($comsiss_state == 1) {
  372. //M('lionfish_comshop_member')->where( array('member_id' => $member['member_id'] ) )->save( array('comsiss_state' => 1, 'comsiss_time' => $time) );
  373. //检测是否存在账户,没有就新建
  374. D('Home/Commission')->become_commiss_member($member['member_id']);
  375. //TODO....sendmsg 发送成为分销商的信息
  376. }
  377. else {
  378. M('lionfish_comshop_member')->where( array('member_id' => $member['member_id']) )->save( array('comsiss_state' => 0, 'comsiss_time' => 0, 'is_comsiss_audit'=>1) );
  379. }
  380. }
  381. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  382. }
  383. public function check_agent(){
  384. $_GPC = I('request.');
  385. $id = intval($_GPC['id']);
  386. $comsiss_state = intval($_GPC['state']);
  387. $members = M('lionfish_comshop_member')->field('member_id,openid,we_openid,comsiss_state')->where( 'member_id in( ' . $id . ' )' )->select();
  388. $time = time();
  389. foreach ($members as $member) {
  390. if ($member['comsiss_state'] === $comsiss_state) {
  391. continue;
  392. }
  393. if ($comsiss_state == 1) {
  394. //M('lionfish_comshop_member')->where( array('member_id' => $member['member_id'] ) )->save( array('comsiss_state' => 1, 'comsiss_time' => $time) );
  395. //检测是否存在账户,没有就新建
  396. D('Home/Commission')->become_commiss_member($member['member_id']);
  397. //TODO....sendmsg 发送成为分销商的信息
  398. }else {
  399. M('lionfish_comshop_member')->where( array('member_id' => $member['member_id']) )->save( array('comsiss_state' => 2, 'comsiss_time' => 0) );
  400. }
  401. }
  402. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  403. }
  404. public function nextchild_list()
  405. {
  406. $_GPC = I('request.');
  407. $member_id = $_GPC['id'];
  408. $pindex = max(1, intval($_GPC['page']));
  409. $psize = 20;
  410. $size = 20;
  411. $offset = ($pindex - 1) * $size;
  412. $keyword = $_GPC['keyword'];
  413. $this->keyword = $keyword;
  414. $this->member_id = $member_id;
  415. $where = '';
  416. if( !empty($keyword) )
  417. {
  418. $where .= " and ( username like '%{$keyword}%' or telephone like '%{$keyword}%' ) ";
  419. }
  420. $level = D('Home/Front')->get_config_by_name('commiss_level');
  421. $level_1_ids = array();
  422. $level_2_ids = array();
  423. $level_3_ids = array();
  424. $member_id_arr = array($member_id);
  425. if( $level == 1 )
  426. {
  427. $list = array();
  428. $sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_member
  429. where 1 {$where} and agentid in (".implode(',', $member_id_arr).")
  430. order by member_id desc limit {$offset},{$size}";
  431. $list = M()->query($sql);
  432. foreach( $list as $vv )
  433. {
  434. $level_1_ids[$vv['id']] = $vv['id'];
  435. }
  436. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX') .
  437. 'lionfish_comshop_member WHERE 1 ' . "{$where} and agentid in (".implode(',', $member_id_arr).") " );
  438. $total = $total_arr[0]['count'];
  439. }else if( $level == 2 )
  440. {
  441. $list = array();
  442. $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  443. where 1 and agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
  444. $list1 = M()->query($sql);
  445. if( !empty($list1) )
  446. {
  447. foreach( $list1 as $vv )
  448. {
  449. $level_1_ids[$vv['member_id']] = $vv['member_id'];
  450. }
  451. $level_sql2 =" select member_id from ".C('DB_PREFIX').
  452. "lionfish_comshop_member where 1 and
  453. agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  454. where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
  455. $list2 = M()->query($level_sql2);
  456. if( !empty($list2) || !empty($list1) )
  457. {
  458. foreach( $list2 as $vv )
  459. {
  460. $level_2_ids[$vv['member_id']] = $vv['member_id'];
  461. }
  462. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  463. if(!empty($level_2_ids))
  464. {
  465. foreach($level_2_ids as $vv)
  466. {
  467. $need_ids[] = $vv;
  468. }
  469. }
  470. $sql =" select * from ".C('DB_PREFIX').
  471. "lionfish_comshop_member where 1 {$where} and
  472. member_id in (".implode(',', $need_ids ).") order by member_id desc limit {$offset},{$size}";
  473. $list = M()->query($sql);
  474. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').
  475. 'lionfish_comshop_member WHERE 1 ' . "{$where} and member_id in (".implode(',', $need_ids).") " );
  476. $total = $total_arr[0]['count'];
  477. }
  478. }
  479. }else if( $level == 3 ){
  480. $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  481. where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
  482. $list1 = M()->query($sql);
  483. if( !empty($list1) )
  484. {
  485. foreach( $list1 as $vv )
  486. {
  487. $level_1_ids[$vv['member_id']] = $vv['member_id'];
  488. }
  489. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  490. $level_sql2 =" select * from ".C('DB_PREFIX').
  491. "lionfish_comshop_member where
  492. agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  493. where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
  494. $list2 = M()->query($level_sql2);
  495. if( !empty($list2) )
  496. {
  497. foreach( $list2 as $vv )
  498. {
  499. $level_2_ids[$vv['member_id']] = $vv['member_id'];
  500. }
  501. if(!empty($level_2_ids))
  502. {
  503. foreach($level_2_ids as $vv)
  504. {
  505. $need_ids[] = $vv;
  506. }
  507. }
  508. }
  509. $level_sql3 =" select * from ".C('DB_PREFIX').
  510. "lionfish_comshop_member where
  511. agentid in (".implode(',', $need_ids).") order by member_id desc ";
  512. $list3 = M()->query($level_sql3 );
  513. if( !empty($list3) )
  514. {
  515. foreach( $list3 as $vv )
  516. {
  517. $level_3_ids[$vv['member_id']] = $vv['member_id'];
  518. }
  519. if(!empty($level_3_ids))
  520. {
  521. foreach($level_3_ids as $vv)
  522. {
  523. $need_ids[] = $vv;
  524. }
  525. }
  526. }
  527. $level_sql3 =" select * from ".C('DB_PREFIX').
  528. "lionfish_comshop_member where 1 {$where} and member_id in (".implode(',',$need_ids).") order by member_id desc limit {$offset},{$size}";
  529. $list = M()->query($level_sql3);
  530. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX') .
  531. 'lionfish_comshop_member WHERE 1 ' . "{$where} and member_id in (".implode(',', $need_ids).") " );
  532. $total = $total_arr[0]['count'];
  533. }
  534. }
  535. if( !empty($list) )
  536. {
  537. foreach($list as $key => $val)
  538. {
  539. //member_id
  540. $val['child_level'] = 1;
  541. if( isset($level_2_ids[$val['member_id']]) )
  542. {
  543. $val['child_level'] = 2;
  544. }
  545. else if( isset($level_3_ids[$val['member_id']]) )
  546. {
  547. $val['child_level'] = 3;
  548. }
  549. //$val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
  550. $list[$key] = $val;
  551. }
  552. }
  553. $this->_GPC = $_GPC;
  554. $pager = pagination2($total, $pindex, $psize);
  555. $this->list = $list;
  556. $this->pager = $pager;
  557. $this->display();
  558. }
  559. public function clear_haibao()
  560. {
  561. M('lionfish_comshop_member')->where( "member_id > 0" )->save( array('commiss_qrcode' => '') );
  562. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  563. }
  564. public function sharedetail()
  565. {
  566. $_GPC = I('request.');
  567. $id = $_GPC['id'];
  568. $keyword = $_GPC['keyword'];
  569. $condition = ' and share_id = '.$id." and (agentid=0 or agentid = {$id}) ";
  570. $pindex = max(1, intval($_GPC['page']));
  571. $psize = 20;
  572. if (!empty($_GPC['keyword'])) {
  573. $_GPC['keyword'] = trim($_GPC['keyword']);
  574. $condition .= ' and ( username like "%'.$_GPC['keyword'].'%" or realname like "%'.$_GPC['keyword'].'%" or telephone like "%'.$_GPC['keyword'].'%") ';
  575. }
  576. if ($_GPC['comsiss_state'] != '') {
  577. $condition .= ' and comsiss_state=' . intval($_GPC['comsiss_state']);
  578. }
  579. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_member
  580. WHERE 1 " . $condition . ' order by member_id desc ';
  581. if (empty($_GPC['export'])) {
  582. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  583. }
  584. $list = M()->query($sql);
  585. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member WHERE 1 ' . $condition);
  586. $total = $total_arr[0]['count'];
  587. if ($_GPC['export'] == '1') {
  588. foreach ($list as &$row) {
  589. $row['sharename'] = empty($val['share_parent_info']) ? '总店' : $val['share_parent_info']['username'];
  590. $row['parentname'] = empty($val['parent_info']) ? '总店' : $val['parent_info']['username'];
  591. $next_member_count_arr = D('Home/Commission')->get_member_all_next_count($val['member_id']);
  592. $row['level1'] = $next_member_count_arr['level_1_count'];
  593. $row['level2'] = $next_member_count_arr['level_2_count'];
  594. $row['level3'] = $next_member_count_arr['level_3_count'];
  595. //commission_info
  596. $row['commission_total'] = $row['commission_info']['commission_total'];
  597. $row['getmoney'] = $row['commission_info']['getmoney'];
  598. $row['createtime'] = date('Y-m-d H:i', $row['create_time']);
  599. $row['comsiss_time'] = empty($row['comsiss_time']) ? '': date('Y-m-d H:i', $row['comsiss_time']);
  600. $row['groupname'] = empty($row['groupname']) ? '无分组' : $row['groupname'];
  601. $row['levelname'] = empty($row['levelname']) ? '普通等级' : $row['levelname'];
  602. $row['parentname'] = empty($row['parentname']) ? '总店' : '[' . $row['agentid'] . ']' . $row['parentname'];
  603. $row['statusstr'] = empty($row['status']) ? '' : '通过';
  604. $row['followstr'] = empty($row['followed']) ? '' : '已关注';
  605. }
  606. unset($row);
  607. $columns = array(
  608. array('title' => 'ID', 'field' => 'member_id', 'width' => 12),
  609. array('title' => '用户名', 'field' => 'username', 'width' => 12),
  610. array('title' => '手机号', 'field' => 'telephone', 'width' => 12),
  611. array('title' => 'openid', 'field' => 'we_openid', 'width' => 24),
  612. array('title' => '推荐人', 'field' => 'sharename', 'width' => 12),
  613. array('title' => '上级', 'field' => 'parentname', 'width' => 12),
  614. array('title' => '分销商等级', 'field' => 'commission_level_name', 'width' => 12),
  615. array('title' => '下线分销商总数', 'field' => 'next_member_count', 'width' => 12),
  616. array('title' => '一级下线分销商数', 'field' => 'level1', 'width' => 12),
  617. array('title' => '二级下线分销商数', 'field' => 'level2', 'width' => 12),
  618. array('title' => '三级下线分销商数', 'field' => 'level3', 'width' => 12),
  619. array('title' => '累计佣金', 'field' => 'commission_total', 'width' => 12),
  620. array('title' => '打款佣金', 'field' => 'getmoney', 'width' => 12),
  621. array('title' => '注册时间', 'field' => 'createtime', 'width' => 12),
  622. array('title' => '成为分销商时间', 'field' => 'comsiss_time', 'width' => 12),
  623. array('title' => '审核状态', 'field' => 'comsiss_time', 'width' => 12)
  624. );
  625. D('Seller/Excel')->export($list, array('title' => $id.'下级分享人数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  626. }
  627. $pager = pagination2($total, $pindex, $psize);
  628. $this->_GPC = $_GPC;
  629. $this->pager = $pager;
  630. $this->list = $list;
  631. $this->keyword = $keyword;
  632. $this->display();
  633. }
  634. public function distribution()
  635. {
  636. $_GPC = I('request.');
  637. $condition = ' and comsiss_flag = 1 ';
  638. $pindex = max(1, intval($_GPC['page']));
  639. $psize = 20;
  640. $type = 0;
  641. if( isset($_GPC['type']) && !empty($_GPC['type']) )
  642. {
  643. $type = $_GPC['type'];
  644. }
  645. switch( $type )
  646. {
  647. case 0:
  648. break;
  649. case 1:
  650. $condition .= " and comsiss_state=1 or is_comsiss_audit=1 ";
  651. break;
  652. case 2:
  653. $condition .= " and comsiss_state=0 and is_comsiss_audit=0 ";
  654. break;
  655. }
  656. if (!empty($_GPC['keyword'])) {
  657. $_GPC['keyword'] = trim($_GPC['keyword']);
  658. $condition .= ' and ( username like "%'.$_GPC['keyword'].'%" or realname like "%'.$_GPC['keyword'].'%" or telephone like "%'.$_GPC['keyword'].'%") ';
  659. }
  660. $starttime = strtotime( date('Y-m-d')." 00:00:00" );
  661. $endtime = $starttime + 86400;
  662. if( isset($_GPC['searchtime']) && $_GPC['searchtime'] == 'create_time' )
  663. {
  664. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  665. $starttime = strtotime($_GPC['time']['start']);
  666. $endtime = strtotime($_GPC['time']['end']);
  667. $condition .= ' AND comsiss_time >= '.$starttime.' AND comsiss_time <= '.$endtime.' ';
  668. }
  669. }
  670. $this->starttime = $starttime;
  671. $this->endtime = $endtime;
  672. /**
  673. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  674. $starttime = strtotime($_GPC['time']['start']);
  675. $endtime = strtotime($_GPC['time']['end']);
  676. $condition .= ' AND comsiss_time >= '.$starttime.' AND comsiss_time <= '.$endtime;
  677. }
  678. **/
  679. if ($_GPC['comsiss_state'] != '') {
  680. $condition .= ' and comsiss_state=' . intval($_GPC['comsiss_state']);
  681. if($_GPC['comsiss_state'] == 0){
  682. $condition .= ' and comsiss_state=' . intval($_GPC['comsiss_state']).' and is_comsiss_audit=0 ';
  683. }else if($_GPC['comsiss_state'] == 1){
  684. $condition .= ' and comsiss_state=' . intval($_GPC['comsiss_state']).' or is_comsiss_audit=1 ';
  685. }
  686. }
  687. if ($_GPC['commission_level_id'] != '') {
  688. $condition .= ' and commission_level_id =' . intval($_GPC['commission_level_id']);
  689. }
  690. if( isset($_GPC['groupid']) && !empty($_GPC['groupid']) )
  691. {
  692. $condition .= ' and groupid = '.$_GPC['groupid'];
  693. }
  694. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_member
  695. WHERE 1 " . $condition . ' order by member_id desc ';
  696. if (empty($_GPC['export'])) {
  697. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  698. }
  699. $list = M()->query($sql);
  700. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member WHERE 1 ' . $condition);
  701. $total = $total_arr[0]['count'];
  702. $level_list = M()->query("select * from ".C('DB_PREFIX').
  703. 'lionfish_comshop_commission_level order by id asc ');
  704. $keys_level = array();
  705. $keys_level[0] = D('Home/Front')->get_config_by_name('commission_levelname');
  706. if( empty($keys_level[0]) )
  707. {
  708. $keys_level[0] = '普通等级';
  709. }
  710. foreach($level_list as $vv)
  711. {
  712. $keys_level[$vv['id']] = $vv['levelname'];
  713. }
  714. foreach( $list as $key => $val )
  715. {
  716. //普通等级
  717. $val['share_parent_info'] = D('Home/Commission')->get_share_name($val['share_id']);
  718. $val['parent_info'] = D('Home/Commission')->get_parent_info($val['agentid']);
  719. $next_member_count_arr = D('Home/Commission')->get_member_all_next_count($val['member_id']);
  720. $val['next_member_count'] = $next_member_count_arr['total'];
  721. $val['commission_level_name'] = $keys_level[$val['commission_level_id']];
  722. $val['commission_info'] = D('Home/Commission')->get_commission_info( $val['member_id'] );
  723. $list[$key] = $val;
  724. }
  725. if ($_GPC['export'] == '1') {
  726. foreach ($list as &$row) {
  727. $row['sharename'] = empty($val['share_parent_info']) ? '总店' : $val['share_parent_info']['username'];
  728. $row['parentname'] = empty($val['parent_info']) ? '总店' : $val['parent_info']['username'];
  729. $next_member_count_arr = D('Home/Commission')->get_member_all_next_count($val['member_id']);
  730. $row['level1'] = $next_member_count_arr['level_1_count'];
  731. $row['level2'] = $next_member_count_arr['level_2_count'];
  732. $row['level3'] = $next_member_count_arr['level_3_count'];
  733. //commission_info
  734. $row['commission_total'] = $row['commission_info']['commission_total'];
  735. $row['getmoney'] = $row['commission_info']['getmoney'];
  736. $row['createtime'] = date('Y-m-d H:i', $row['create_time']);
  737. $row['comsiss_time'] = empty($row['comsiss_time']) ? '': date('Y-m-d H:i', $row['comsiss_time']);
  738. $row['groupname'] = empty($row['groupname']) ? '无分组' : $row['groupname'];
  739. $row['levelname'] = empty($row['levelname']) ? '普通等级' : $row['levelname'];
  740. $row['parentname'] = empty($row['parentname']) ? '总店' : '[' . $row['agentid'] . ']' . $row['parentname'];
  741. $row['statusstr'] = empty($row['status']) ? '' : '通过';
  742. $row['followstr'] = empty($row['followed']) ? '' : '已关注';
  743. }
  744. unset($row);
  745. $columns = array(
  746. array('title' => 'ID', 'field' => 'member_id', 'width' => 12),
  747. array('title' => '用户名', 'field' => 'username', 'width' => 12),
  748. array('title' => '手机号', 'field' => 'telephone', 'width' => 12),
  749. array('title' => 'openid', 'field' => 'we_openid', 'width' => 24),
  750. array('title' => '推荐人', 'field' => 'sharename', 'width' => 12),
  751. array('title' => '上级', 'field' => 'parentname', 'width' => 12),
  752. array('title' => '分销商等级', 'field' => 'commission_level_name', 'width' => 12),
  753. array('title' => '下线分销商总数', 'field' => 'next_member_count', 'width' => 12),
  754. array('title' => '一级下线分销商数', 'field' => 'level1', 'width' => 12),
  755. array('title' => '二级下线分销商数', 'field' => 'level2', 'width' => 12),
  756. array('title' => '三级下线分销商数', 'field' => 'level3', 'width' => 12),
  757. array('title' => '累计佣金', 'field' => 'commission_total', 'width' => 12),
  758. array('title' => '打款佣金', 'field' => 'getmoney', 'width' => 12),
  759. array('title' => '注册时间', 'field' => 'createtime', 'width' => 12),
  760. array('title' => '成为分销商时间', 'field' => 'comsiss_time', 'width' => 12),
  761. array('title' => '审核状态', 'field' => 'comsiss_time', 'width' => 12)
  762. );
  763. D('Seller/Excel')->export($list, array('title' => '分销商数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  764. }
  765. $pager = pagination2($total, $pindex, $psize);
  766. $this->pager = $pager;
  767. $this->_GPC = $_GPC;
  768. $s_id = 1 ;
  769. if(SELLERUID != 1)
  770. {
  771. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  772. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  773. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  774. $perms2 = explode(",", $perms1);
  775. if(in_array("user/user/index", $perms2)){
  776. $s_id = 1 ;
  777. } else {
  778. $s_id = 0 ;
  779. }
  780. }
  781. $this->s_id = $s_id;
  782. $this->list =$list;
  783. $this->display();
  784. }
  785. private function modifylevel()
  786. {
  787. $_GPC = I('request.');
  788. $id = trim($_GPC['id']);
  789. $set = D('Seller/Config')->get_all_config();
  790. if ($id == 'default') {
  791. $level = array('id' => 'default', 'levelname' => empty($set['commission_levelname']) ? '默认等级' : $set['commission_levelname'], 'commission1' => $set['commission1'], 'commission2' => $set['commission2'], 'commission3' => $set['commission3']);
  792. }
  793. else {
  794. $level = M('lionfish_comshop_commission_level')->where( array('id' => intval($id) ) )->find();
  795. }
  796. if (IS_POST) {
  797. $data = array(
  798. 'levelname' => trim($_GPC['levelname']),
  799. 'commission1' => trim(trim($_GPC['commission1']), '%'),
  800. 'commission2' => trim(trim($_GPC['commission2']), '%'),
  801. 'commission3' => trim(trim($_GPC['commission3']), '%'),
  802. 'ordermoney' => $_GPC['ordermoney']
  803. );
  804. if (!empty($id)) {
  805. if ($id == 'default') {
  806. $updatecontent = '<br/>等级名称: ' . $set['levelname'] . '->' . $data['levelname'] . '<br/>一级佣金比例: ' . $set['commission1'] . '->' . $data['commission1'] . '<br/>二级佣金比例: ' . $set['commission2'] . '->' . $data['commission2'] . '<br/>三级佣金比例: ' . $set['commission3'] . '->' . $data['commission3'];
  807. $set_data = array();
  808. $set_data['commission_levelname'] = $data['levelname'];
  809. $set_data['commission1'] = $data['commission1'];
  810. $set_data['commission2'] = $data['commission2'];
  811. $set_data['commission3'] = $data['commission3'];
  812. D('Seller/Config')->update($set_data);
  813. }
  814. else {
  815. $updatecontent = '<br/>等级名称: ' . $level['levelname'] . '->' . $data['levelname'] . '<br/>一级佣金比例: ' . $level['commission1'] . '->' . $data['commission1'] . '<br/>二级佣金比例: ' . $level['commission2'] . '->' . $data['commission2'] . '<br/>三级佣金比例: ' . $level['commission3'] . '->' . $data['commission3'];
  816. M('lionfish_comshop_commission_level')->where( array('id' => $id) )->save( $data );
  817. }
  818. }
  819. else {
  820. M('lionfish_comshop_commission_level')->add($data);
  821. }
  822. show_json(1, array('url' => U('distribution/level')));
  823. }
  824. $this->level = $level;
  825. $this->display('Distribution/modifylevel');
  826. }
  827. public function withdrawallist()
  828. {
  829. $_GPC = I('request.');
  830. $condition = ' ';
  831. $pindex = max(1, intval($_GPC['page']));
  832. $psize = 20;
  833. $keyword = $_GPC['keyword'];
  834. if (!empty($_GPC['keyword'])) {
  835. $_GPC['keyword'] = trim($_GPC['keyword']);
  836. $condition.="and (id = '{$keyword}' or username like '%{$keyword}%' or realname like '%{$keyword}%' or bankaccount like '%{$keyword}%')";
  837. }
  838. $starttime = strtotime( date('Y-m-d')." 00:00:00" );
  839. $endtime = $starttime + 86400;
  840. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  841. $starttime = strtotime($_GPC['time']['start']);
  842. $endtime = strtotime($_GPC['time']['end']);
  843. $condition .= ' AND addtime >= '.$starttime.' AND addtime <= '.$endtime;
  844. }
  845. $this->starttime = $starttime;
  846. $this->endtime = $endtime;
  847. if ($_GPC['comsiss_state'] != '') {
  848. $condition .= ' and state=' . intval($_GPC['comsiss_state']);
  849. }
  850. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_member_tixian_order o left join " .C('DB_PREFIX')."lionfish_comshop_member m
  851. on o.member_id = m.member_id WHERE 1 " . $condition . ' order by id desc ';
  852. if (empty($_GPC['export'])) {
  853. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  854. }
  855. $community_tixian_fee = D('Home/Front')->get_config_by_name('community_tixian_fee');
  856. $list = M()->query($sql);
  857. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').
  858. 'lionfish_comshop_member_tixian_order o left join '.C('DB_PREFIX').'lionfish_comshop_member m on o.member_id = m.member_id WHERE 1 ' . $condition);
  859. $total = $total_arr[0]['count'];
  860. $this->_GPC = $_GPC;
  861. //ims_lionfish_community_head_commiss
  862. foreach( $list as $key => $val )
  863. {
  864. //普通等级
  865. $member_info = M('lionfish_comshop_member')->field('username,avatar,we_openid,telephone')->where( array('member_id' => $val['member_id'] ) )->find();
  866. $val['member_info'] = $member_info;
  867. $list[$key] = $val;
  868. }
  869. if ($_GPC['export'] == '1') {
  870. foreach($list as $key =>&$row)
  871. {
  872. $row['username'] = $row['member_info']['username'];
  873. $row['telephone'] = $row['member_info']['telephone'];
  874. $row['bankname'] = $row['bankname'];
  875. if( $row['type'] == 1 )
  876. {
  877. $row['bankname'] = '余额';
  878. }elseif( $row['type'] == 2 ){
  879. $row['bankname'] = '微信零钱';
  880. }elseif($row['type'] == 3){
  881. $row['bankname'] = '支付宝';
  882. }
  883. $row['bankaccount'] = "\t".$row['bankaccount'];
  884. $row['bankusername'] = $row['bankusername'];
  885. $row['get_money'] = $row['money']-$row['service_charge_money'];
  886. $row['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
  887. if(!empty($row['shentime']))
  888. {
  889. $row['shentime'] = date('Y-m-d H:i:s', $row['shentime']);
  890. }
  891. if($row['state'] ==0)
  892. {
  893. $row['state'] = '待审核';
  894. }else if($row[state] ==1)
  895. {
  896. $row['state'] = '已审核,打款';
  897. }else if($row[state] ==2){
  898. $row['state'] = '已拒绝';
  899. }
  900. }
  901. unset($row);
  902. $columns = array(
  903. array('title' => 'ID', 'field' => 'id', 'width' => 12),
  904. array('title' => '用户名', 'field' => 'username', 'width' => 12),
  905. array('title' => '联系方式', 'field' => 'telephone', 'width' => 12),
  906. array('title' => '打款银行', 'field' => 'bankname', 'width' => 24),
  907. array('title' => '打款账户', 'field' => 'bankaccount', 'width' => 24),
  908. array('title' => '真实姓名', 'field' => 'bankusername', 'width' => 24),
  909. array('title' => '申请提现金额', 'field' => 'money', 'width' => 24),
  910. array('title' => '手续费', 'field' => 'service_charge_money', 'width' => 24),
  911. array('title' => '到账金额', 'field' => 'get_money', 'width' => 24),
  912. array('title' => '申请时间', 'field' => 'addtime', 'width' => 24),
  913. array('title' => '审核时间', 'field' => 'shentime', 'width' => 24),
  914. array('title' => '状态', 'field' => 'state', 'width' => 24)
  915. );
  916. D('Seller/Excel')->export($list, array('title' => '会员分销提现数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  917. }
  918. $pager = pagination2($total, $pindex, $psize);
  919. $this->pager = $pager;
  920. $this->list = $list;
  921. $this->display();
  922. }
  923. public function agent_check_apply()
  924. {
  925. $_GPC = I('request.');
  926. $commission_model = D('Home/Commission');
  927. $id = intval($_GPC['id']);
  928. if (empty($id)) {
  929. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  930. }
  931. $comsiss_state = intval($_GPC['state']);
  932. $apply_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member_tixian_order
  933. WHERE id in( ' . $id . ' ) ');
  934. $time = time();
  935. foreach ($apply_list as $apply) {
  936. if ($apply['state'] == $comsiss_state || $apply['state'] == 1 || $apply['state'] == 2) {
  937. continue;
  938. }
  939. $money = $apply['money'];
  940. if ($comsiss_state == 1) {
  941. switch( $apply['type'] )
  942. {
  943. case 1:
  944. $result = $commission_model->send_apply_yuer( $apply['id'] );
  945. break;
  946. case 2:
  947. $result = $commission_model->send_apply_weixin_yuer( $apply['id'] );
  948. break;
  949. case 3:
  950. $result = $commission_model->send_apply_alipay_bank( $apply['id'] );
  951. break;
  952. case 4:
  953. $result = $commission_model->send_apply_alipay_bank( $apply['id'] );
  954. break;
  955. }
  956. if( $result['code'] == 1)
  957. {
  958. show_json(0, array('url' => $_SERVER['HTTP_REFERER'],'message'=>$result['msg']) );
  959. }
  960. //检测是否存在账户,没有就新建
  961. //TODO....检测是否微信提现到零钱,如果是,那么就准备打款吧
  962. $commission_model->send_apply_success_msg($apply['id']);
  963. }
  964. else if ($comsiss_state == 2) {
  965. M('lionfish_comshop_member_tixian_order')->where( array('id' => $apply['id'] ) )->save( array('state' => 2, 'shentime' => $time) );
  966. //退回冻结的货款
  967. M()->execute("update ".C('DB_PREFIX')."lionfish_comshop_member_commiss set money=money+{$money},dongmoney=dongmoney-{$money}
  968. where member_id=".$apply['member_id']);
  969. }
  970. else {
  971. M('lionfish_comshop_member_tixian_order')->where( array('id' => $apply['id']) )->save( array('state' => 0, 'shentime' => 0) );
  972. }
  973. }
  974. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  975. }
  976. }
  977. ?>