SupplyController.class.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  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 SupplyController extends CommonController {
  16. public function index()
  17. {
  18. $export = I('get.export',0);
  19. $condition = ' 1=1 ';
  20. $pindex = $pindex = I('get.page', 1);
  21. $psize = 20;
  22. $keyword = I('get.keyword','','trim');
  23. if (!empty($keyword)) {
  24. $condition .= ' and ( shopname like "'.'%' . $keyword . '%'.'" or name like "'.'%' . $keyword . '%'.'" or mobile like "'.'%' . $keyword . '%'.'" ) ';
  25. }
  26. $this->keyword = $keyword;
  27. $time = I('get.time');
  28. if (!empty($time['start']) && !empty($time['end'])) {
  29. $starttime = strtotime($time['start']);
  30. $endtime = strtotime($time['end']);
  31. $this->starttime = $starttime;
  32. $this->endtime = $endtime;
  33. $condition .= ' AND apptime >= '.$starttime.' AND apptime <= '.$endtime;
  34. }
  35. $comsiss_state = I('get.comsiss_state','');
  36. if ($comsiss_state != '') {
  37. $condition .= ' and state=' . intval($comsiss_state);
  38. }
  39. $this->comsiss_state = $comsiss_state;
  40. $sql = 'SELECT * FROM ' . C('DB_PREFIX') . "lionfish_comshop_supply \r\n
  41. WHERE " . $condition . ' order by id desc ';
  42. if (empty($export)) {
  43. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  44. }
  45. $list = M()->query($sql);
  46. $total = M('lionfish_comshop_supply')->where($condition)->count();
  47. foreach( $list as $key => $val )
  48. {
  49. //goods_count
  50. $goods_count = M('lionfish_comshop_good_common')->where( array('supply_id' => $val['id']) )->count();
  51. $val['goods_count'] = $goods_count;
  52. $list[$key] = $val;
  53. }
  54. if ($export == '1') {
  55. foreach ($list as &$row) {
  56. $row['username'] = $val['member_info']['username'];
  57. $row['we_openid'] = $val['member_info']['we_openid'];
  58. $row['commission_total'] = 0;
  59. $row['getmoney'] = 0;
  60. $row['fulladdress'] = $row['province_name'].$row['city_name'].$row['area_name'].$row['country_name'].$row['address'];
  61. $row['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
  62. $row['apptime'] = date('Y-m-d H:i:s', $row['apptime']);
  63. $row['state'] = $row['state'] == 1 ? '已审核':'未审核';
  64. }
  65. unset($row);
  66. $columns = array(
  67. array('title' => 'ID', 'field' => 'id', 'width' => 12),
  68. array('title' => '店铺名称', 'field' => 'shopname', 'width' => 12),
  69. array('title' => '供应商名称', 'field' => 'name', 'width' => 12),
  70. array('title' => '联系方式', 'field' => 'mobile', 'width' => 12),
  71. array('title' => '商品数量', 'field' => 'goods_count', 'width' => 12),
  72. array('title' => '注册时间', 'field' => 'addtime', 'width' => 12),
  73. array('title' => '成为团长时间', 'field' => 'apptime', 'width' => 12),
  74. array('title' => '审核状态', 'field' => 'state', 'width' => 12)
  75. );
  76. D('Seller/Excel')->export($list, array('title' => '供应商数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  77. }
  78. $pager = pagination2($total, $pindex, $psize);
  79. $this->list = $list;
  80. $this->pager = $pager;
  81. $supply_is_open_mobilemanage = D('Home/Front')->get_config_by_name('supply_is_open_mobilemanage');
  82. if( empty($supply_is_open_mobilemanage) || $supply_is_open_mobilemanage == 0 )
  83. {
  84. $supply_is_open_mobilemanage = 0;
  85. }
  86. $this->supply_is_open_mobilemanage = $supply_is_open_mobilemanage;
  87. $this->display('Supply/supply');
  88. }
  89. public function authority()
  90. {
  91. $_GPC = I('request.');
  92. if (IS_POST) {
  93. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  94. $data['supply_can_goods_updown'] = isset($data['supply_can_goods_updown']) ? $data['supply_can_goods_updown'] : 2;
  95. $data['supply_can_vir_count'] = isset($data['supply_can_vir_count']) ? $data['supply_can_vir_count'] : 2;
  96. $data['supply_can_goods_istop'] = isset($data['supply_can_goods_istop']) ? $data['supply_can_goods_istop'] : 2;
  97. $data['supply_can_goods_isindex'] = isset($data['supply_can_goods_isindex']) ? $data['supply_can_goods_isindex'] : 2;
  98. $data['supply_can_goods_sendscore'] = isset($data['supply_can_goods_sendscore']) ? $data['supply_can_goods_sendscore'] : 2;
  99. $data['supply_can_goods_newbuy'] = isset($data['supply_can_goods_newbuy']) ? $data['supply_can_goods_newbuy'] : 2;
  100. $data['supply_can_look_headinfo'] = isset($data['supply_can_look_headinfo']) ? $data['supply_can_look_headinfo'] : 2;
  101. $data['supply_can_nowrfund_order'] = isset($data['supply_can_nowrfund_order']) ? $data['supply_can_nowrfund_order'] : 2;
  102. $data['supply_can_goods_spike'] = isset($data['supply_can_goods_spike']) ? $data['supply_can_goods_spike'] : 2;
  103. $data['supply_can_distribution_sale'] = isset($data['supply_can_distribution_sale']) ? $data['supply_can_distribution_sale'] : 2;
  104. $data['supply_can_confirm_delivery'] = isset($data['supply_can_confirm_delivery']) ? $data['supply_can_confirm_delivery'] : 2;
  105. $data['supply_can_confirm_receipt'] = isset($data['supply_can_confirm_receipt']) ? $data['supply_can_confirm_receipt'] : 2;
  106. D('Seller/Config')->update($data);
  107. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  108. }
  109. $data = D('Seller/Config')->get_all_config();
  110. $this->data = $data;
  111. $this->_GPC = $_GPC;
  112. $this->display();
  113. }
  114. public function distributionpostal()
  115. {
  116. $_GPC = I('request.');
  117. if (IS_POST) {
  118. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  119. $data['supply_commiss_tixianway_yuer'] = isset($data['supply_commiss_tixianway_yuer']) ? $data['supply_commiss_tixianway_yuer'] : 1;
  120. $data['supply_commiss_tixianway_weixin'] = isset($data['supply_commiss_tixianway_weixin']) ? $data['supply_commiss_tixianway_weixin'] : 1;
  121. $data['supply_commiss_tixianway_alipay'] = isset($data['supply_commiss_tixianway_alipay']) ? $data['supply_commiss_tixianway_alipay'] : 1;
  122. $data['supply_commiss_tixianway_bank'] = isset($data['supply_commiss_tixianway_bank']) ? $data['supply_commiss_tixianway_bank'] : 1;
  123. $data['supply_commiss_tixianway_weixin_offline'] = isset($data['supply_commiss_tixianway_weixin_offline']) ? $data['supply_commiss_tixianway_weixin_offline'] : 1;
  124. D('Seller/Config')->update($data);
  125. show_json(1, array('url' => U('Supply/distributionpostal')) );
  126. }
  127. $data = D('Seller/Config')->get_all_config();
  128. $this->data = $data;
  129. $this->display();
  130. }
  131. public function agent_check_first()
  132. {
  133. $_GPC = I('request.');
  134. //dump($_GPC);
  135. $id = intval($_GPC['id']);
  136. $this->type = $_GPC['type'];
  137. if ( IS_POST ) {
  138. $type = $_GPC['type'];
  139. //dump($type);die;
  140. $time = time();
  141. M('lionfish_comshop_supply')->where( array('id' => $id ) )->save( array('type' => $type,'state' => 1, 'apptime' => $time) );
  142. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  143. }
  144. $this->id = $id;
  145. include $this->display();
  146. }
  147. public function agent_tixian()
  148. {
  149. $_GPC = I('request.');
  150. $id = intval($_GPC['id']);
  151. if (empty($id)) {
  152. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  153. }
  154. $comsiss_state = intval($_GPC['state']);
  155. $members = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_supply_tixian_order
  156. WHERE id in( ' . $id . ' ) ');
  157. $time = time();
  158. $open_weixin_qiye_pay = D('Home/Front')->get_config_by_name('open_weixin_qiye_pay');
  159. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  160. require_once $lib_path."/Weixin/lib/WxPay.Api.php";
  161. foreach ($members as $member) {
  162. if ($member['state'] === $comsiss_state) {
  163. continue;
  164. }
  165. if ($comsiss_state == 1) {
  166. if( $member['state'] == 0 )
  167. {
  168. if( $member['supply_apply_type'] == 1 )
  169. {
  170. if( !empty($open_weixin_qiye_pay) && $open_weixin_qiye_pay == 1 )
  171. {
  172. $supper_info = M('lionfish_comshop_supply')->field('member_id')->where( array('id' => $member['supply_id'] ) )->find();
  173. if( !empty($supper_info['member_id']) && $supper_info['member_id'] > 0 )
  174. {
  175. $mb_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $supper_info['member_id'] ) )->find();
  176. $partner_trade_no = build_order_no($member['id']);
  177. $desc = date('Y-m-d H:i:s', $member['addtime']).'申请的提现已到账';
  178. $username = $member['bankaccount'];
  179. $amount = round($member['money'] - $member['service_charge'], 2) * 100;
  180. $openid = $mb_info['we_openid'];
  181. $res = \WxPayApi::payToUser($openid,$amount,$username,$desc,$partner_trade_no,$_W['uniacid']);
  182. if(empty($res) || $res['result_code'] =='FAIL')
  183. {
  184. show_json(0, array('message' => $res['err_code_des'] ));
  185. }
  186. }else{
  187. show_json(0, array('message' => '请编辑供应商资料绑定会员,才能进行微信零钱提现'));
  188. }
  189. }else{
  190. show_json(0, array('message' => '请前往团长提现设置开启微信企业付款,供应商提现公用资料'));
  191. }
  192. }
  193. M('lionfish_supply_tixian_order')->where( array('id' => $member['id'] ) )->save( array('state' => 1, 'shentime' => $time) );
  194. //打款
  195. M()->execute("update ".C('DB_PREFIX')."lionfish_supply_commiss set dongmoney=dongmoney-{$member[money]},getmoney=getmoney+{$member[money]}
  196. where supply_id=".$member['supply_id']);
  197. }
  198. }
  199. else {
  200. if( $member['state'] == 0 )
  201. {
  202. M('lionfish_supply_tixian_order')->where( array('id' => $member['id']) )->save( array('state' => 2, 'shentime' => 0) );
  203. //退款
  204. M()->execute( "update ".C('DB_PREFIX')."lionfish_supply_commiss set dongmoney=dongmoney-{$member[money]},money=money+{$member[money]}
  205. where supply_id=".$member['supply_id'] );
  206. }
  207. }
  208. }
  209. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  210. }
  211. public function test()
  212. {
  213. $list = M('lionfish_supply_commiss_order')->where( array('state' =>0) )->select();
  214. foreach( $list as $val )
  215. {
  216. M('lionfish_supply_commiss_order')->where( array('id' => $val['id']) )->save( array('money' => $val['money'] - $val['head_commiss_money'] ) );
  217. }
  218. echo 'success';
  219. die();
  220. }
  221. //---begin
  222. public function floworder()
  223. {
  224. $_GPC = I('request.');
  225. $supper_info = get_agent_logininfo();
  226. $condition = ' a.supply_id='. $supper_info['id'].' ';
  227. $pindex = max(1, intval($_GPC['page']));
  228. $psize = 20;
  229. $searchtime = I('request.searchtime','');
  230. $time = I('request.time');
  231. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  232. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  233. $this->starttime = $starttime;
  234. $this->endtime = $endtime;
  235. $this->searchtime = $searchtime;
  236. if( !empty($searchtime) )
  237. {
  238. switch( $searchtime )
  239. {
  240. case 'create':
  241. //下单时间 date_added
  242. $condition .= " and a.addtime >={$starttime} and a.addtime <= {$endtime}";
  243. break;
  244. }
  245. }
  246. $keyword = I('get.keyword','');
  247. $this->keyword = $keyword;
  248. if (!(empty($keyword))) {
  249. $condition .= " AND (a.order_id = '{$keyword}' or b.name LIKE '%{$keyword}%') ";
  250. }
  251. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_supply_commiss_order as a left join ' . C('DB_PREFIX'). 'lionfish_comshop_order_goods as b
  252. on a.order_goods_id = b.order_goods_id WHERE ' . $condition . ' order by a.id desc ';
  253. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  254. {
  255. }else{
  256. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  257. }
  258. $list = M()->query($sql);
  259. $sql = 'SELECT COUNT(a.id) as count FROM ' . C('DB_PREFIX'). 'lionfish_supply_commiss_order as a left join ' . C('DB_PREFIX'). 'lionfish_comshop_order_goods as b
  260. on a.order_goods_id = b.order_goods_id WHERE ' . $condition ;
  261. $total_arr = M()->query($sql);
  262. $total = $total_arr[0]['count'];
  263. // $total = M('lionfish_supply_commiss_order')->where( $condition )->count();
  264. foreach( $list as $key => $val )
  265. {
  266. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $val['order_goods_id'] ) )->find();
  267. $val['goods_name'] = $order_goods['name'];
  268. $val['option_sku'] = D('Seller/Order')->get_order_option_sku($order_goods['order_id'], $order_goods['order_goods_id']);
  269. $commission_list = M('lionfish_community_head_commiss_order')->where( "order_id=".$order_goods['order_id']." and order_goods_id=".$order_goods['order_goods_id'] )->select();
  270. $val['commission_list'] = $commission_list;
  271. $order = M('lionfish_comshop_order')->where( array('order_id' => $val['order_id'] ) )->find();
  272. $val['order_num_alias'] = $order['order_num_alias'];
  273. $val['delivery'] = $order['delivery'];
  274. // 1 5 7??12 4 6 11
  275. if( $order['delivery'] == 'localtown_delivery' && ($order['order_status_id'] == 4 || $order['order_status_id'] == 6 || $order['order_status_id'] == 11 ) ){
  276. $val['status'] = 1;
  277. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $val['order_id'] ) )->find();
  278. $val['shipping_money'] = $shipping_money['shipping_money']*$order_goods['fenbi_li'];
  279. }
  280. //违约金
  281. $deduct_fee = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $val['order_id'] ) )->find();
  282. $val['goods_deduct_fee'] = $deduct_fee['deduct_fee'] * $order_goods['fenbi_li'];
  283. $list[$key] = $val;
  284. }
  285. if( isset($_GPC['export']) && $_GPC['export'] == 1 )
  286. {
  287. $columns = array(
  288. array('title' => '订单id', 'field' => 'order_id', 'width' => 16),
  289. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 32),
  290. array('title' => '商品名称', 'field' => 'goods_name', 'width' => 32),
  291. array('title' => '金额', 'field' => 'total_money', 'width' => 16),
  292. array('title' => '运费', 'field' => 'shipping_fare', 'width' => 16),
  293. array('title' => '包装费', 'field' => 'packing_fare', 'width' => 16),
  294. array('title' => '配送员佣金', 'field' => 'shipping_money', 'width' => 16),
  295. array('title' => '团长佣金', 'field' => 'head_commiss_money', 'width' => 16),
  296. array('title' => '服务费比例', 'field' => 'comunity_blili', 'width' => 16),
  297. array('title' => '服务费金额', 'field' => 'fuwu_money', 'width' => 16),
  298. array('title' => '实收金额', 'field' => 'money', 'width' => 16),
  299. array('title' => '状态', 'field' => 'state', 'width' => 16),
  300. );
  301. $exportlist = array();
  302. foreach($list as $val)
  303. {
  304. $tmp_exval = array();
  305. $tmp_exval['order_id'] = $val['order_id'];
  306. $tmp_exval['order_num_alias'] = "\t".$val['order_num_alias']."\t";
  307. $tmp_exval['goods_name'] = $val['goods_name'].$val['option_sku'];
  308. $tmp_exval['total_money'] = $val['total_money'];
  309. $tmp_exval['shipping_fare'] = $val['shipping_fare'];
  310. $tmp_exval['packing_fare'] = $val['packing_fare']*$val['quantity'];
  311. $tmp_exval['shipping_money'] ='-'.$val['shipping_money'];
  312. $tmp_exval['head_commiss_money'] = '-'.$val['head_commiss_money'];
  313. $tmp_exval['comunity_blili'] = $val['comunity_blili'].'%';
  314. $tmp_exval['fuwu_money'] = '-'.( round($val['total_money']*$val['comunity_blili']/100,2));
  315. $tmp_exval['money'] = $val['money'];
  316. if( $val[state] ==2 ){
  317. $tmp_exval['state'] = '订单取消';
  318. }else if( $val[state] ==1 ){
  319. $tmp_exval['state'] = '已结算';
  320. }else{
  321. $tmp_exval['state'] = '待结算';
  322. }
  323. $exportlist[] = $tmp_exval;
  324. }
  325. D('Seller/Excel')->export($exportlist, array('title' => '资金流水', 'columns' => $columns));
  326. }
  327. $pager = pagination2($total, $pindex, $psize);
  328. $this->list = $list;
  329. $this->pager = $pager;
  330. $this->display('Supply/floworder');
  331. }
  332. public function admintixianlist()
  333. {
  334. $_GPC = I('request.');
  335. $condition = ' 1 ';
  336. $supply_id = I('request.supply_id','');
  337. if(!empty($supply_id)){
  338. $condition = $condition. " and supply_id=".$supply_id;
  339. }
  340. $pindex = max(1, intval($_GPC['page']));
  341. $psize = 20;
  342. $sql = 'SELECT * FROM ' . C('DB_PREFIX') . "lionfish_supply_tixian_order
  343. WHERE " . $condition . ' order by state asc , id desc ';
  344. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  345. $list = M()->query($sql);
  346. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').
  347. 'lionfish_supply_tixian_order WHERE ' . $condition );
  348. $total = $total_arr[0]['count'];
  349. foreach( $list as $key => $val )
  350. {
  351. $supper_info = D('Home/Front')->get_supply_info($val['supply_id']);
  352. $val['supper_info'] = $supper_info;
  353. $list[$key] = $val;
  354. }
  355. $pager = pagination2($total, $pindex, $psize);
  356. $this->list = $list;
  357. $this->pager = $pager;
  358. $this->display();
  359. }
  360. public function tixianlist()
  361. {
  362. $_GPC = I('request.');
  363. $supper_info = get_agent_logininfo();
  364. $condition = ' supply_id= '.$supper_info['id'];
  365. $pindex = max(1, intval($_GPC['page']));
  366. $psize = 20;
  367. $sql = 'SELECT * FROM ' . C('DB_PREFIX') . "lionfish_supply_tixian_order
  368. WHERE " . $condition . ' order by id desc ';
  369. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  370. $list = M()->query($sql);
  371. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').
  372. 'lionfish_supply_tixian_order WHERE ' . $condition);
  373. $total = $total_arr[0]['count'];
  374. foreach( $list as $key => $val )
  375. {
  376. $list[$key] = $val;
  377. }
  378. $pager = pagination2($total, $pindex, $psize);
  379. $supply_commiss = M('lionfish_supply_commiss')->where( array('supply_id' => $supper_info['id'] ) )->find();
  380. //TODO...
  381. if( empty($supply_commiss) )
  382. {
  383. $lionfish_supply_commiss_data = array();
  384. $lionfish_supply_commiss_data['supply_id'] = $supper_info['id'];
  385. $lionfish_supply_commiss_data['money'] = 0;
  386. $lionfish_supply_commiss_data['dongmoney'] = 0;
  387. $lionfish_supply_commiss_data['getmoney'] = 0;
  388. M('lionfish_supply_commiss')->add( $lionfish_supply_commiss_data );
  389. $supply_commiss = array();
  390. $supply_commiss['money'] = 0;
  391. $supply_commiss['dongmoney'] = 0;
  392. $supply_commiss['getmoney'] = 0;
  393. }
  394. $supply_tixian_moneyfree = D('Home/Front')->get_config_by_name('supply_tixian_moneyfree');
  395. if( !isset($supply_tixian_moneyfree) || $supply_tixian_moneyfree <= 0 )
  396. {
  397. $supply_tixian_moneyfree = 0;
  398. }
  399. $this->supply_tixian_moneyfree = $supply_tixian_moneyfree;
  400. $this->supply_commiss = $supply_commiss;
  401. $this->list = $list;
  402. $this->pager = $pager;
  403. $this->display('Supply/tixianlist');
  404. }
  405. public function apply_money()
  406. {
  407. $_GPC = I('request.');
  408. $supper_info = get_agent_logininfo();
  409. $supply_min_apply_money = D('Home/Front')->get_config_by_name('supply_min_money');
  410. if( empty($supply_min_apply_money) )
  411. {
  412. $supply_min_apply_money = 0;
  413. }
  414. $supply_commiss = M('lionfish_supply_commiss')->where( array('supply_id' =>$supper_info['id'] ) )->find();
  415. $last_tixian_order = array('bankname' =>'微信','bankaccount' => '','bankusername' => '' ,'supply_apply_type' => -1 );
  416. $lionfish_supply_tixian_order = M('lionfish_supply_tixian_order')->where( array('supply_id' =>$supper_info['id'] ) )->order('id desc')->find();
  417. if( !empty($lionfish_supply_tixian_order) )
  418. {
  419. $last_tixian_order['bankname'] = $lionfish_supply_tixian_order['bankname'];
  420. $last_tixian_order['bankaccount'] = $lionfish_supply_tixian_order['bankaccount'];
  421. $last_tixian_order['bankusername'] = $lionfish_supply_tixian_order['bankusername'];
  422. $last_tixian_order['supply_apply_type'] = $lionfish_supply_tixian_order['supply_apply_type'];
  423. }
  424. $this->supply_min_apply_money = $supply_min_apply_money;
  425. $this->supply_commiss = $supply_commiss;
  426. $this->last_tixian_order = $last_tixian_order;
  427. $this->lionfish_supply_tixian_order = $lionfish_supply_tixian_order;
  428. $sup_info = M('lionfish_comshop_supply')->where( array('id' => $supper_info['id'] ) )->find();
  429. //member_id
  430. $bind_member = array();
  431. if( $sup_info['member_id'] > 0 )
  432. {
  433. $bind_member = M('lionfish_comshop_member')->where( array('member_id' => $sup_info['member_id'] ) )->find();
  434. }
  435. $this->bind_member = $bind_member;
  436. if (IS_POST) {
  437. $supply_apply_type = $_GPC['supply_apply_type'];
  438. if( !isset($supply_apply_type) )
  439. {
  440. show_json(0, array('message' => '请选择打款类型'));
  441. }
  442. //1 微信 2 支付宝 3银行卡
  443. //bankname bankaccount bankusername
  444. $weixin_account = $_GPC['weixin_account'];
  445. $alipay_account = $_GPC['alipay_account'];
  446. $alipay_truename = $_GPC['alipay_truename'];
  447. $card_name = $_GPC['card_name'];
  448. $card_account = $_GPC['card_account'];
  449. $card_username = $_GPC['card_username'];
  450. $weixin_account_xx = $_GPC['weixin_account_xx'];
  451. $ti_money = floatval( $_GPC['ti_money'] );
  452. if($supply_apply_type == 3){
  453. $reg = '/^[\d]{16,19}$/ ';
  454. if(!preg_match($reg,$card_account,$match)){
  455. show_json(0, array('message' => '银行卡账户格式错误'));
  456. }
  457. }
  458. if($ti_money < $supply_min_apply_money){
  459. show_json(0, array('message' => '最低提现'.$supply_min_apply_money));
  460. }
  461. if($ti_money <=0){
  462. show_json(0, array('message' => '最低提现大于0元'));
  463. }
  464. if($ti_money > $supply_commiss['money']){
  465. show_json(0, array('message' => '当前最多提现'.$supply_commiss['money']));
  466. }
  467. $supper_in = M('lionfish_comshop_supply')->field('commiss_bili')->where( array('id' => $supper_info['id'] ) )->find();
  468. $supply_tixian_moneyfree = D('Home/Front')->get_config_by_name('supply_tixian_moneyfree');
  469. if( !isset($supply_tixian_moneyfree) || $supply_tixian_moneyfree <= 0 )
  470. {
  471. $supply_tixian_moneyfree = 0;
  472. }
  473. $ins_data = array();
  474. $ins_data['supply_id'] = $supper_info['id'];
  475. $ins_data['money'] = $ti_money;
  476. $ins_data['service_charge'] = round( ($supply_tixian_moneyfree * $ti_money) / 100 ,2);
  477. $ins_data['server_bili'] = $supply_tixian_moneyfree;
  478. $ins_data['state'] = 0;
  479. $ins_data['shentime'] = 0;
  480. $ins_data['is_send_fail'] = 0;
  481. $ins_data['fail_msg'] = '';
  482. $ins_data['supply_apply_type'] = $supply_apply_type;
  483. //1 微信 2 支付宝 3银行卡
  484. if($supply_apply_type == 1)
  485. {
  486. $ins_data['bankname'] = '微信零钱';
  487. $ins_data['bankaccount'] = $weixin_account;
  488. $ins_data['bankusername'] = '';
  489. }else if($supply_apply_type == 2){
  490. $ins_data['bankname'] = '支付宝';
  491. $ins_data['bankaccount'] = $alipay_account;
  492. $ins_data['bankusername'] = $alipay_truename;
  493. }else if($supply_apply_type == 3){
  494. $ins_data['bankname'] = $card_name;
  495. $ins_data['bankaccount'] = $card_account;
  496. $ins_data['bankusername'] = $card_username;
  497. }else if($supply_apply_type == 4){
  498. $ins_data['bankname'] = '微信私下转';
  499. $ins_data['bankaccount'] = $weixin_account_xx;
  500. $ins_data['bankusername'] = '';
  501. }
  502. $ins_data['addtime'] = time();
  503. M('lionfish_supply_tixian_order')->add($ins_data);
  504. M('lionfish_supply_commiss')->where( array('supply_id' => $supper_info['id'] ) )->setInc('money',-$ti_money);
  505. M('lionfish_supply_commiss')->where( array('supply_id' => $supper_info['id'] ) )->setInc('dongmoney',$ti_money);
  506. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  507. }
  508. $data = D('Seller/Config')->get_all_config();
  509. $supply_commiss_tixianway_weixin = !isset($data['supply_commiss_tixianway_weixin']) || (isset($data['supply_commiss_tixianway_weixin']) && $data['supply_commiss_tixianway_weixin'] ==2) ? 2 : 0;
  510. $supply_commiss_tixianway_alipay = !isset($data['supply_commiss_tixianway_alipay']) || (isset($data['supply_commiss_tixianway_alipay']) && $data['supply_commiss_tixianway_alipay'] ==2) ? 2 : 0;
  511. $supply_commiss_tixianway_bank = !isset($data['supply_commiss_tixianway_bank']) || (isset($data['supply_commiss_tixianway_bank']) && $data['supply_commiss_tixianway_bank'] ==2) ? 2 : 0;
  512. $supply_commiss_tixianway_weixin_offline = !isset($data['supply_commiss_tixianway_weixin_offline']) || (isset($data['supply_commiss_tixianway_weixin_offline']) && $data['supply_commiss_tixianway_weixin_offline'] ==2) ? 2 : 0;
  513. $this->data = $data;
  514. $this->supply_commiss_tixianway_weixin = $supply_commiss_tixianway_weixin;
  515. $this->supply_commiss_tixianway_alipay = $supply_commiss_tixianway_alipay;
  516. $this->supply_commiss_tixianway_bank = $supply_commiss_tixianway_bank;
  517. $this->supply_commiss_tixianway_weixin_offline = $supply_commiss_tixianway_weixin_offline;
  518. $supply_tixian_moneyfree = D('Home/Front')->get_config_by_name('supply_tixian_moneyfree');
  519. if( !isset($supply_tixian_moneyfree) || $supply_tixian_moneyfree <= 0 )
  520. {
  521. $supply_tixian_moneyfree = 0;
  522. }
  523. $this->commiss_bili = $supply_tixian_moneyfree;
  524. $this->display();
  525. }
  526. /**
  527. 供应商登录
  528. **/
  529. public function login()
  530. {
  531. $this->display();
  532. }
  533. /**
  534. 供应商登录提交密码
  535. **/
  536. public function login_do()
  537. {
  538. $_GPC = I('request.');
  539. //mobile:mobile, password:password}
  540. $mobile = trim($_GPC['mobile']);
  541. $password = trim($_GPC['password']);
  542. if( empty($mobile) || empty($password) )
  543. {
  544. echo json_encode( array('code' => 1, 'msg' => '请填写您的账号密码!') );
  545. die();
  546. }
  547. $record = array( );
  548. $temp = M('lionfish_comshop_supply')->where( array('login_name' => $mobile ) )->find();
  549. if( !empty($temp) )
  550. {
  551. $password = md5( $temp["login_slat"].$password );
  552. if( $password == $temp["login_password"] )
  553. {
  554. $record = $temp;
  555. }
  556. }
  557. if( !empty($record) )
  558. {
  559. if( $record["state"] == 0)
  560. {
  561. echo json_encode( array('code' => 1, 'msg' => '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决!') );
  562. die();
  563. }
  564. if( $record["type"] == 0)
  565. {
  566. //echo json_encode( array('code' => 1, 'msg' => '平台供应商无须登录供应商后台!') );
  567. //die();
  568. }
  569. if( !empty($_W["siteclose"]) )
  570. {
  571. echo json_encode( array('code' => 1, 'msg' => "站点已关闭,关闭原因:" . $_W["setting"]["copyright"]["reason"] ) );
  572. die();
  573. }
  574. if (C('USER_AUTH_ON')) {
  575. unset($_SESSION[C('USER_AUTH_KEY')]);
  576. unset($_SESSION[C('ADMIN_AUTH_KEY')]);
  577. }
  578. session('seller_auth', array());
  579. session('seller_auth_sign', -1);
  580. $auth = array(
  581. 'uid' => $record["id"],
  582. 'shopname' => $temp['shopname'],
  583. 'username' => $temp['shopname'],
  584. 'type' => $record['type'],
  585. 'role' => 'agenter',
  586. 'role_id' => 0,
  587. 'last_login_time' => $seller['s_last_login_time'],
  588. );
  589. session('agent_auth', $auth);
  590. session('agent_auth_sign', data_auth_sign($auth));
  591. if( empty($forward) )
  592. {
  593. $forward = $_GPC["forward"];
  594. }
  595. if( empty($forward) )
  596. {
  597. $forward = U('index/index');
  598. }
  599. //message("欢迎回来," . $record["title"] . "。", $forward, "success" );
  600. cookie('last_login_page',2);
  601. echo json_encode( array('code' => 0, 'url' => $forward ) );
  602. die();
  603. }
  604. else
  605. {
  606. echo json_encode( array('code' => 1, 'msg' => "您的账号密码错误!") );
  607. die();
  608. }
  609. die();
  610. }
  611. //---end
  612. public function config()
  613. {
  614. $gpc = I('request.');
  615. if (IS_POST) {
  616. $data = ((is_array($gpc['data']) ? $gpc['data'] : array()));
  617. D('Seller/Config')->update($data);
  618. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  619. }
  620. $data = D('Seller/Config')->get_all_config();
  621. $this->data = $data;
  622. $this->display();
  623. }
  624. public function baseconfig()
  625. {
  626. $gpc = I('request.');
  627. //dump($gpc);
  628. if (IS_POST) {
  629. $data = ((is_array($gpc['data']) ? $gpc['data'] : array()));
  630. D('Seller/Config')->update($data);
  631. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  632. }
  633. $data = D('Seller/Config')->get_all_config();
  634. $this->data = $data;
  635. $this->display();
  636. }
  637. public function agent_mobilemanage()
  638. {
  639. $id = I('get.id',0);
  640. if (empty($id)) {
  641. $ids = I('post.ids');
  642. $id = (is_array($ids) ? implode(',', $ids) : 0);
  643. }
  644. $is_open_mobilemanage = I('request.is_open_mobilemanage');
  645. $members = M('lionfish_comshop_supply')->field('id,is_open_mobilemanage')->where( array('id' => array('in', $id) ) )->select();
  646. $time = time();
  647. foreach ($members as $member) {
  648. if ($member['is_open_mobilemanage'] === $is_open_mobilemanage) {
  649. continue;
  650. }
  651. M('lionfish_comshop_supply')->where(array('id' => $member['id']))->save( array('is_open_mobilemanage' => $is_open_mobilemanage ) );
  652. }
  653. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  654. }
  655. public function agent_check()
  656. {
  657. $id = I('get.id',0);
  658. if (empty($id)) {
  659. $ids = I('post.ids');
  660. $id = (is_array($ids) ? implode(',', $ids) : 0);
  661. }
  662. $comsiss_state = I('request.state');
  663. $members = M('lionfish_comshop_supply')->field('id,state')->where( array('id' => array('in', $id) ) )->select();
  664. $time = time();
  665. foreach ($members as $member) {
  666. if ($member['state'] === $comsiss_state) {
  667. continue;
  668. }
  669. if ($comsiss_state == 1) {
  670. $res = M('lionfish_comshop_supply')->where(array('id' => $member['id']))->save( array('state' => 1, 'apptime' => $time) );
  671. }
  672. else if($comsiss_state == 2)
  673. {
  674. M('lionfish_comshop_supply')->where( array('id' => $member['id']) )->save( array('state' => 2, 'apptime' => $time ) );
  675. }
  676. else if($comsiss_state == 3)
  677. {
  678. M('lionfish_comshop_supply')->where( array('id' => $member['id']) )->save( array('state' => 3, 'is_open_mobilemanage' => 0,'apptime' => $time ) );
  679. }
  680. else {
  681. M('lionfish_comshop_supply')->where(array('id' => $member['id']))->save( array('state' => 0, 'apptime' => 0) );
  682. }
  683. }
  684. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  685. }
  686. public function zhenquery()
  687. {
  688. $kwd = I('request.keyword','','trim');
  689. $is_ajax = I('request.is_ajax',0,'intval');
  690. $condition = ' state=1 ';
  691. if (!empty($kwd)) {
  692. $condition .= ' AND ( `shopname` LIKE "'.'%' . $kwd . '%'.'" or `name` like "'.'%' . $kwd . '%'.'" or `mobile` like "'.'%' . $kwd . '%'.'" )';
  693. }
  694. /**
  695. 分页开始
  696. **/
  697. $page = I('request.page',1,'intval');
  698. $page = max(1, $page);
  699. $page_size = 10;
  700. /**
  701. 分页结束
  702. **/
  703. $ds = M('lionfish_comshop_supply')->where( $condition )->order('id desc')->limit( (($page - 1) * $page_size) . ',' . $page_size )->select();
  704. $total = M('lionfish_comshop_supply')->where( $condition )->count();
  705. $ret_html = '';
  706. foreach ($ds as &$value) {
  707. $value['nickname'] = htmlspecialchars($value['username'], ENT_QUOTES);
  708. $value['logo'] = tomedia($value['logo']);
  709. $value['supply_id'] = $value['id'];
  710. if($value['type'] == 1){
  711. $supplytype = "独立供应商";
  712. }else{
  713. $supplytype = "平台供应商";
  714. }
  715. if($is_ajax == 1)
  716. {
  717. $ret_html .= '<tr>';
  718. $ret_html .= '<td><img src="'.$value['logo'].'" style="width:30px;height:30px;padding1px;border:1px solid #ccc" />';
  719. $ret_html .= '<td style="width:100px;">'.$value['shopname'].'</td>';
  720. $ret_html .= '<td>'.$supplytype.'</td>';
  721. $ret_html .= '<td>'.$value['name'].'</td>';
  722. $ret_html .= '<td>'.$value['mobile'].'</td>';
  723. $ret_html .= '<td style="width:80px;"><a href="javascript:;" class="choose_dan_link" data-json=\''.json_encode($value).'\'>选择</a></td>';
  724. $ret_html .= '</tr>';
  725. }
  726. }
  727. $pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
  728. unset($value);
  729. if( $is_ajax == 1 )
  730. {
  731. echo json_encode( array('code' => 0, 'html' => $ret_html,'pager' => $pager) );
  732. die();
  733. }
  734. $this->ds = $ds;
  735. $this->pager = $pager;
  736. $this->display('Supply/query');
  737. }
  738. public function modifypassword()
  739. {
  740. if( IS_POST )
  741. {
  742. $datas = I('post.data');
  743. $repassword = $datas['repassword'];
  744. $password = $datas['password'];
  745. if( empty($password) || empty($repassword) )
  746. {
  747. show_json(0, array('message' => '密码不能为空'));
  748. die();
  749. }
  750. if( $password != $repassword )
  751. {
  752. show_json(0, array('message' => '两次输入的密码不一致'));
  753. die();
  754. }
  755. $supper_info = get_agent_logininfo();
  756. $info = M('lionfish_comshop_supply')->where( array('id' => $supper_info['id'] ) )->find();
  757. $slat = $info['login_slat'];
  758. $data = array();
  759. $data['login_password'] = md5( $slat.$password );
  760. $res = M('lionfish_comshop_supply')->where( array('id' => $supper_info['id'] ) )->save( $data );
  761. if($res)
  762. {
  763. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  764. die();
  765. }
  766. }
  767. $this->display();
  768. }
  769. public function addsupply()
  770. {
  771. $id = I('get.id', 0);
  772. $supply_is_open_mobilemanage = D('Home/Front')->get_config_by_name('supply_is_open_mobilemanage');
  773. if( empty($supply_is_open_mobilemanage) || $supply_is_open_mobilemanage == 0 )
  774. {
  775. $supply_is_open_mobilemanage = 0;
  776. }
  777. if (IS_POST) {
  778. $data = array();
  779. $data['id'] = $id;
  780. $data['shopname'] = I('post.shopname');
  781. $data['logo'] = I('post.logo');
  782. $data['name'] = I('post.name');
  783. $data['mobile'] = I('post.mobile');
  784. $data['state'] = I('post.state');
  785. //is_open_mobilemanage
  786. $data['is_open_mobilemanage'] = I('post.is_open_mobilemanage', 0);
  787. if( $supply_is_open_mobilemanage == 0 )
  788. {
  789. $data['is_open_mobilemanage'] = 0;
  790. }
  791. $data['login_name'] = I('post.login_name');
  792. $supply_info = M('lionfish_comshop_supply')->where( array('login_name' => $data['login_name'] ) )->find();
  793. if($id > 0)
  794. {
  795. if($supply_info && $id != $supply_info['id']){
  796. show_json(0, array('message' => '该登录账户已使用!'));
  797. }
  798. }else{
  799. if($supply_info){
  800. show_json(0, array('message' => '该登录账户已使用!'));
  801. }
  802. }
  803. $data['login_password'] = I('post.login_password');
  804. $data['type'] = I('post.type');
  805. $data['commiss_bili'] = I('post.commiss_bili');
  806. $data['member_id'] = I('post.member_id');
  807. $goods_industrial = I('post.goods_industrial');
  808. $data['qualifications'] = serialize($goods_industrial);
  809. $data['storename'] = I('post.storename');
  810. $data['banner'] = I('post.banner');
  811. $data['apptime'] = time();
  812. $data['addtime'] = time();
  813. $rs = D('Seller/supply')->modify_supply($data);
  814. if($rs)
  815. {
  816. show_json(1, array('url' => U('supply/index')));
  817. }else{
  818. show_json(0, array('message' => '保存失败'));
  819. }
  820. //show_json(1, array('url' => U('distribution/level')));
  821. // show_json(0, array('message' => '未找到订单!'));
  822. //show_json(1, array('url' => referer()));
  823. }
  824. if($id > 0)
  825. {
  826. $item = M('lionfish_comshop_supply')->where( array('id' => $id) )->find();
  827. $this->item = $item;
  828. $saler = array();
  829. if( $item['member_id'] > 0 )
  830. {
  831. $saler = M('lionfish_comshop_member')->field('member_id, username as nickname,avatar')->where( array('member_id' => $item['member_id'] ) )->find();
  832. }
  833. $piclist = array();
  834. if( !empty($item['qualifications']) )
  835. {
  836. $item['qualifications'] = unserialize($item['qualifications']);
  837. foreach($item['qualifications'] as $val)
  838. {
  839. //$piclist[] = tomedia($val);
  840. $piclist[] = array('image' =>$val, 'thumb' => tomedia($val) ); //$val['image'];
  841. }
  842. }
  843. $this->piclist = $piclist;
  844. $this->saler = $saler;
  845. }
  846. $this->supply_is_open_mobilemanage = $supply_is_open_mobilemanage;
  847. $this->id = $id;
  848. $this->display();
  849. }
  850. public function changename()
  851. {
  852. $_GPC = I('request.');
  853. $id = intval($_GPC['id']);
  854. //ids
  855. if (empty($id)) {
  856. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  857. }
  858. if (empty($id)) {
  859. show_json(0, array('message' => '参数错误'));
  860. }
  861. $type = trim($_GPC['type']);
  862. $value = trim($_GPC['value']);
  863. $items = M('lionfish_supply_tixian_order')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  864. foreach ($items as $item ) {
  865. M('lionfish_supply_tixian_order')->where( array('id' => $item['id']) )->save( array('bankaccount' => $value) );
  866. }
  867. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  868. }
  869. public function deletesupply()
  870. {
  871. $_GPC = I('request.');
  872. $id = intval($_GPC['id']);
  873. if (empty($id)) {
  874. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  875. }
  876. $items = M('lionfish_comshop_supply')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  877. foreach ($items as $item ) {
  878. M('lionfish_comshop_supply')->where( array('id' => $item['id']) )->delete();
  879. }
  880. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  881. }
  882. }
  883. ?>