SupplyController.class.php 37 KB

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