DistributionController.class.php 41 KB

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