LocaltownController.class.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. * 拼团模块
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class LocaltownController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. /**
  21. *
  22. * 模拟数据填充
  23. */
  24. public function send_data()
  25. {
  26. $list = M('lionfish_comshop_orderdistribution_order')->where( array('state' => 1) )->select();
  27. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  28. if($open_redis_server == 1) {
  29. $redis = D('Seller/Redisorder')->get_redis_object_do();
  30. }
  31. foreach( $list as $val )
  32. {
  33. $lon = $val['shop_lon'];
  34. $lat = $val['shop_lat'];
  35. $redis->getRedis()->rawCommand('geoadd', '_aashop', $lon, $lat, $val['id'] );
  36. }
  37. echo 'ok';
  38. die();
  39. }
  40. /**
  41. 获取待抢的订单
  42. **/
  43. public function get_localtown_delivery()
  44. {
  45. $_GPC = I('request.');
  46. $token = $_GPC['token'];
  47. $lon = isset($_GPC['lon']) ? $_GPC['lon'] : '106.611160';
  48. $lat = isset($_GPC['lat']) ? $_GPC['lat'] : '29.647202';
  49. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  50. $member_id = $weprogram_token['member_id'];
  51. if( empty($member_id) )
  52. {
  53. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  54. die();
  55. }
  56. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  57. if( $orderdistribution_id <= 0 )
  58. {
  59. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  60. die();
  61. }
  62. $orderdistribution_info = D('Home/LocaltownSnatch')->get_distribution_info_by_memberid( $member_id );
  63. //$member_id = $weprogram_token['member_id'];
  64. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  65. if($open_redis_server == 1) {
  66. $redis = D('Seller/Redisorder')->get_redis_object_do();
  67. }
  68. if(!empty($orderdistribution_info['store_id'])){//独立供应商订单
  69. $order_list = $redis->getRedis()->rawCommand('georadius', '_distributionorder_'.$orderdistribution_info['store_id'], $lon, $lat, '10000', 'km', 'ASC');
  70. }else{
  71. $order_list = $redis->getRedis()->rawCommand('georadius', '_distributionorder', $lon, $lat, '10000', 'km', 'ASC');
  72. }
  73. if( count($order_list) > 35 )
  74. {
  75. $order_list = array_slice( $order_list ,0,35);
  76. }
  77. if( empty($order_list) )
  78. {
  79. echo json_encode( array('code' => 2, 'msg' => '暂无订单可抢') );
  80. die();
  81. }else{
  82. $need_data = array();
  83. foreach( $order_list as $id )
  84. {
  85. $need_data[] = D('Home/LocaltownSnatch')->get_localtown_orderinfo( $id );
  86. }
  87. $new_order_notice = 0;
  88. if($orderdistribution_info['is_new_notice'] == 1){
  89. $new_order_notice = 1;
  90. }
  91. echo json_encode( array('code' => 0, 'data' => $need_data,'new_order_notice'=>$new_order_notice ) );
  92. die();
  93. }
  94. }
  95. // ASC 根据圆心位置,从近到远的返回元素
  96. // DESC 根据圆心位置,从远到近的返回元素
  97. //var_dump($redis->rawCommand('georadius', 'citys', '114', '30', '100', 'km', 'ASC'));
  98. /**
  99. 获取配送员信息
  100. **/
  101. public function get_orderdistribution_info()
  102. {
  103. $_GPC = I('request.');
  104. $token = $_GPC['token'];
  105. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  106. $member_id = $weprogram_token['member_id'];
  107. if( empty($member_id) )
  108. {
  109. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  110. die();
  111. }
  112. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  113. if( $orderdistribution_id <= 0 )
  114. {
  115. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  116. die();
  117. }
  118. //get_distribution_ordercount_bymember_id( $member_id, $state ) 2 待取货 3 配送中 4 已送达
  119. $waite_get_count = D('Home/LocaltownSnatch')->get_distribution_ordercount_bymember_id( $member_id, 2 );//2 待取货
  120. $sending_count = D('Home/LocaltownSnatch')->get_distribution_ordercount_bymember_id( $member_id, 3 );//3 配送中
  121. $sended_count = D('Home/LocaltownSnatch')->get_distribution_ordercount_bymember_id( $member_id, 4 );//4 已送达
  122. $waite_send_list = D('Home/LocaltownSnatch')->get_distribution_waitget_memberlist_by_memberid( $member_id );
  123. $sending_send_list = D('Home/LocaltownSnatch')->get_distribution_sending_memberlist_by_memberid( $member_id );
  124. $orderdistribution_info = D('Home/LocaltownSnatch')->get_distribution_info_by_memberid( $member_id );
  125. $need_data = array();
  126. $need_data['orderdistribution_info'] = $orderdistribution_info;
  127. $need_data['waite_get_count'] = $waite_get_count;
  128. $need_data['sending_count'] = $sending_count;
  129. $need_data['sended_count'] = $sended_count;
  130. $need_data['waite_send_list'] = $waite_send_list;
  131. $need_data['sending_send_list'] = $sending_send_list;
  132. echo json_encode( array('code' => 0 , 'data' => $need_data ) );
  133. die();
  134. //TODO...
  135. }
  136. /**
  137. 获取配送员的相关类型的订单
  138. **/
  139. public function get_distribution_orderlist()
  140. {
  141. $_GPC = I('request.');
  142. $token = $_GPC['token'];
  143. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  144. $member_id = $weprogram_token['member_id'];
  145. if( empty($member_id) )
  146. {
  147. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  148. die();
  149. }
  150. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  151. if( $orderdistribution_id <= 0 )
  152. {
  153. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  154. die();
  155. }
  156. $type = isset($_GPC['type']) && $_GPC['type'] > 0 ? $_GPC['type'] : 2;
  157. $page = isset($_GPC['page']) && $_GPC['page'] > 0 ? $_GPC['page'] : 1;
  158. $perpage = 10;
  159. $offset = ($page - 1) * $perpage;
  160. $orderlist = D('Home/LocaltownSnatch')->get_distribution_orderlist_by_member_id( $member_id, $type, $offset, $perpage );
  161. if( empty($orderlist) )
  162. {
  163. echo json_encode( array('code' => 2, 'msg' => '没有更多数据') );
  164. die();
  165. }else{
  166. echo json_encode( array('code' => 0 , 'data' => $orderlist ) );
  167. die();
  168. }
  169. }
  170. /**
  171. 配送员中心-统计
  172. **/
  173. public function get_distribution_statics()
  174. {
  175. $_GPC = I('request.');
  176. $token = $_GPC['token'];
  177. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  178. $member_id = $weprogram_token['member_id'];
  179. if( empty($member_id) )
  180. {
  181. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  182. die();
  183. }
  184. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  185. if( $orderdistribution_id <= 0 )
  186. {
  187. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  188. die();
  189. }
  190. //累计抢单数
  191. $total_getorder_count = 0;
  192. $wait_send_count = D('Home/LocaltownSnatch')->get_distribution_ordercount_bymember_id( $member_id, 2 );
  193. $sending_count = D('Home/LocaltownSnatch')->get_distribution_ordercount_bymember_id( $member_id, 3 );
  194. $sended_count = D('Home/LocaltownSnatch')->get_distribution_ordercount_bymember_id( $member_id, 4 );
  195. $total_getorder_count = $wait_send_count + $sending_count + $sended_count;
  196. //系统分配订单数
  197. $system_send_ordercount = D('Home/LocaltownSnatch')->get_system_send_ordercount_by_member_id( $member_id );
  198. //累计完成的订单数
  199. $distribution_info = D('Home/LocaltownSnatch')->get_distribution_info_by_memberid( $member_id );
  200. //配送费收入
  201. $commiss_info = D('Home/LocaltownSnatch')->get_commiss_by_orderdistribution_id( $orderdistribution_id );
  202. //return array('money' => 0, 'dongmoney' => 0, 'getmoney' => 0);
  203. $total_commiss_money = round( ($commiss_info['money']+$commiss_info['dongmoney']+$commiss_info['getmoney']), 2 );
  204. $need_data = array();
  205. $need_data['total_getorder_count'] = $total_getorder_count;
  206. $need_data['system_send_ordercount'] = $system_send_ordercount;
  207. $need_data['has_send_count'] = $distribution_info['has_send_count'];
  208. $need_data['total_commiss_money'] = sprintf("%.2f", $total_commiss_money);
  209. echo json_encode( array('code' => 0, 'data' => $need_data) );
  210. die();
  211. }
  212. /**
  213. 获取配送员中心资料
  214. **/
  215. public function get_distribution_center_info()
  216. {
  217. $_GPC = I('request.');
  218. $token = $_GPC['token'];
  219. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  220. $member_id = $weprogram_token['member_id'];
  221. if( empty($member_id) )
  222. {
  223. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  224. die();
  225. }
  226. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  227. if( $orderdistribution_id <= 0 )
  228. {
  229. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  230. die();
  231. }
  232. $orderdistribution_info = D('Home/LocaltownSnatch')->get_distribution_info_by_memberid( $member_id );
  233. //配送费收入
  234. $commiss_info = D('Home/LocaltownSnatch')->get_commiss_by_orderdistribution_id( $orderdistribution_id );
  235. $need_data = array();
  236. $need_data['orderdistribution_info'] = $orderdistribution_info;
  237. $need_data['can_tixian_money'] = !empty($commiss_info['money']) ? $commiss_info['money'] : 0;
  238. echo json_encode( array('code' => 0, 'data' => $need_data ) );
  239. die();
  240. }
  241. /**
  242. 获取会员配送佣金基础数据
  243. **/
  244. public function get_distribution_commission_info()
  245. {
  246. $_GPC = I('request.');
  247. $token = $_GPC['token'];
  248. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  249. $member_id = $weprogram_token['member_id'];
  250. if( empty($member_id) )
  251. {
  252. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  253. die();
  254. }
  255. $orderdistribution_info = M('lionfish_comshop_orderdistribution')->where( array('member_id' => $member_id) )->find();
  256. if( empty($orderdistribution_info) )
  257. {
  258. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  259. die();
  260. }
  261. $store_id = $orderdistribution_info['store_id'];
  262. //最小提现金额
  263. $commiss_min_tixian_money = D('Home/Front')->get_config_by_name('distribution_min_tixian_money');
  264. if($store_id > 0){
  265. $commiss_min_tixian_money = D('Home/Front')->get_supply_config_by_name('distribution_min_tixian_money',$store_id);
  266. }
  267. if( empty($commiss_min_tixian_money) )
  268. {
  269. $commiss_min_tixian_money = 0;
  270. }
  271. $commiss_tixian_bili = D('Home/Front')->get_config_by_name('distribution_tixian_bili');
  272. if($store_id > 0){
  273. $commiss_tixian_bili = D('Home/Front')->get_supply_config_by_name('distribution_tixian_bili',$store_id);
  274. }
  275. if( empty($commiss_tixian_bili) )
  276. {
  277. $commiss_tixian_bili = 0;
  278. }
  279. $member_commiss = M('lionfish_comshop_orderdistribution_commiss')->where( array('orderdistribution_id' => $orderdistribution_info['id'] ) )->find();
  280. $member_commiss['commiss_min_tixian_money'] = $commiss_min_tixian_money;//最小提现金额, 0标识不限制
  281. $member_commiss['commiss_tixian_bili'] = $commiss_tixian_bili;
  282. $member_commiss['total_commiss_money'] = $member_commiss['money'] + $member_commiss['dongmoney'] + $member_commiss['getmoney'];
  283. $commiss_tixianway_yuer = D('Home/Front')->get_config_by_name('distribution_tixianway_yuer');
  284. if($store_id > 0){
  285. $commiss_tixianway_yuer = D('Home/Front')->get_supply_config_by_name('distribution_tixianway_yuer',$store_id);
  286. }
  287. $commiss_tixianway_weixin = D('Home/Front')->get_config_by_name('distribution_tixianway_weixin');
  288. if($store_id > 0){
  289. $commiss_tixianway_weixin = D('Home/Front')->get_supply_config_by_name('distribution_tixianway_weixin',$store_id);
  290. }
  291. $commiss_tixianway_alipay = D('Home/Front')->get_config_by_name('distribution_tixianway_alipay');
  292. if($store_id > 0){
  293. $commiss_tixianway_alipay = D('Home/Front')->get_supply_config_by_name('distribution_tixianway_alipay',$store_id);
  294. }
  295. $commiss_tixianway_bank = D('Home/Front')->get_config_by_name('distribution_tixianway_bank');
  296. if($store_id > 0){
  297. $commiss_tixianway_bank = D('Home/Front')->get_supply_config_by_name('distribution_tixianway_bank',$store_id);
  298. }
  299. if($store_id > 0){
  300. $member_commiss['commiss_tixianway_yuer'] = $commiss_tixianway_yuer == 2 ? 1:0;
  301. $member_commiss['commiss_tixianway_weixin'] = $commiss_tixianway_weixin == 2 ? 1:0;
  302. $member_commiss['commiss_tixianway_alipay'] = empty($commiss_tixianway_alipay) ? 1 : ($commiss_tixianway_alipay == 2 ? 1:0);
  303. $member_commiss['commiss_tixianway_bank'] = $commiss_tixianway_bank == 2 ? 1:0;
  304. }else{
  305. $member_commiss['commiss_tixianway_yuer'] = empty($commiss_tixianway_yuer) ? 1 : ($commiss_tixianway_yuer == 2 ? 1:0);
  306. $member_commiss['commiss_tixianway_weixin'] = empty($commiss_tixianway_weixin) ? 1 : ($commiss_tixianway_weixin == 2 ? 1:0);
  307. $member_commiss['commiss_tixianway_alipay'] = empty($commiss_tixianway_alipay) ? 1 : ($commiss_tixianway_alipay == 2 ? 1:0);
  308. $member_commiss['commiss_tixianway_bank'] = empty($commiss_tixianway_bank) ? 1 : ($commiss_tixianway_bank == 2 ? 1:0);
  309. }
  310. //上一微信真实姓名
  311. $last_weixin_realname = "";
  312. $last_weixin_info = M('lionfish_comshop_orderdistribution_tixian_order')->where( array('member_id' => $member_id, 'type' => 2 ) )->find();
  313. if( !empty($last_weixin_info) )
  314. {
  315. $last_weixin_realname = $last_weixin_info['bankusername'];
  316. }
  317. //上一支付宝账号
  318. $last_alipay_name = '';
  319. $last_alipay_account = '';
  320. $last_alipay_info = M('lionfish_comshop_orderdistribution_tixian_order')->where( array('member_id' => $member_id, 'type' => 3 ) )->find();
  321. if( !empty($last_alipay_info) )
  322. {
  323. $last_alipay_name = $last_alipay_info['bankusername'];
  324. $last_alipay_account = $last_alipay_info['bankaccount'];
  325. }
  326. //上一银行卡信息
  327. $last_bank_bankname = '';
  328. $last_bank_account = '';
  329. $last_bank_name = '';
  330. $last_bank_info = M('lionfish_comshop_orderdistribution_tixian_order')->where( array('member_id' => $member_id, 'type' => 4 ) )->find();
  331. if( !empty($last_bank_info) )
  332. {
  333. $last_bank_bankname = $last_bank_info['bankname'];
  334. $last_bank_account = $last_bank_info['bankaccount'];
  335. $last_bank_name = $last_bank_info['bankusername'];
  336. }
  337. $member_commiss['last_weixin_realname'] = $last_weixin_realname;
  338. $member_commiss['last_alipay_name'] = $last_alipay_name;
  339. $member_commiss['last_alipay_account'] = $last_alipay_account;
  340. $member_commiss['last_bank_bankname'] = $last_bank_bankname;
  341. $member_commiss['last_bank_account'] = $last_bank_account;
  342. $member_commiss['last_bank_name'] = $last_bank_name;
  343. $commiss_tixian_publish = D('Home/Front')->get_config_by_name('distribution_tixian_publish');
  344. if($store_id > 0){
  345. $commiss_tixian_publish = D('Home/Front')->get_supply_config_by_name('distribution_tixian_publish',$store_id);
  346. }
  347. $member_commiss['commiss_tixian_publish'] = htmlspecialchars_decode( $commiss_tixian_publish );
  348. if(empty($member_commiss['money'])){
  349. $member_commiss['money'] = 0;
  350. }
  351. $member_commiss['total_money'] = sprintf('%.2f', $member_commiss['money'] + $member_commiss['dongmoney'] + $member_commiss['getmoney']);
  352. echo json_encode( array('code' =>0,'data' => $member_commiss) );
  353. die();
  354. }
  355. //begin
  356. /**
  357. 会员拼团佣金提现 提交接口
  358. **/
  359. public function tixian_sub()
  360. {
  361. $_GPC = I('request.');
  362. $token = $_GPC['token'];
  363. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  364. $member_id = $weprogram_token['member_id'];
  365. if( empty($member_id) )
  366. {
  367. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  368. die();
  369. }
  370. $orderdistribution_info = M('lionfish_comshop_orderdistribution')->where( array('member_id' => $member_id) )->find();
  371. if( empty($orderdistribution_info) )
  372. {
  373. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  374. die();
  375. }
  376. $store_id = $orderdistribution_info['store_id'];
  377. $result = array('code' => 1,'msg' => '提现失败');
  378. $member_commiss = M('lionfish_comshop_orderdistribution_commiss')->where( array('member_id' => $member_id ) )->find();
  379. $datas = array();
  380. $datas['money'] = $_GPC['money'];
  381. $money = $datas['money'];//I('post.money',0,'floatval');
  382. $type = $_GPC['type'];// 1余额 2 微信 3 支付宝 4 银行
  383. $bankname = isset($_GPC['bankname']) ? $_GPC['bankname'] : ''; //银行名称
  384. $bankaccount = isset($_GPC['bankaccount']) ? $_GPC['bankaccount'] : '';//卡号,支付宝账号 使用该字段
  385. $bankusername = isset($_GPC['bankusername']) ? $_GPC['bankusername'] : '';//持卡人姓名,微信名称,支付宝名称, 使用该字段
  386. $commiss_money_limit = D('Home/Front')->get_config_by_name('distribution_min_tixian_money');
  387. if($store_id > 0){
  388. $commiss_money_limit = D('Home/Front')->get_supply_config_by_name('distribution_min_tixian_money',$store_id);
  389. }
  390. if(!empty($commiss_money_limit) && $commiss_money_limit >0)
  391. {
  392. if($member_commiss['money'] < $commiss_money_limit)
  393. {
  394. $result['msg'] = '佣金满'.$commiss_money_limit.'才能提现';
  395. echo json_encode($result);
  396. die();
  397. }
  398. }
  399. if($money > 0 && $money <= $member_commiss['money'])
  400. {
  401. //判断提现手续费,+ 判断提现金额免审直接到账
  402. $service_charge = D('Home/Front')->get_config_by_name('distribution_tixian_bili');
  403. if($store_id > 0){
  404. $service_charge = D('Home/Front')->get_supply_config_by_name('distribution_tixian_bili',$store_id);
  405. }
  406. $data = array();
  407. $data['member_id'] = $member_id;
  408. $data['money'] = $money;
  409. $data['service_charge'] = $service_charge;
  410. $data['service_charge_money'] = round( ($money * $service_charge) /100 ,2);
  411. $data['state'] = 0;
  412. $data['shentime'] = 0;
  413. $data['type'] = $type;
  414. $data['bankname'] = $bankname;
  415. $data['bankaccount'] = $bankaccount;
  416. $data['bankusername'] = $bankusername;
  417. $data['addtime'] = time();
  418. M('lionfish_comshop_orderdistribution_tixian_order')->add($data);
  419. $com_arr = array();
  420. $com_arr['money'] = $member_commiss['money'] - $money;
  421. $com_arr['dongmoney'] = $member_commiss['dongmoney'] + $money;
  422. M('lionfish_comshop_orderdistribution_commiss')->where( array('member_id' => $member_id ) )->setInc('money',-$money);
  423. M('lionfish_comshop_orderdistribution_commiss')->where( array('member_id' => $member_id ) )->setInc('dongmoney',$money);
  424. $result = array('code' => 0,'msg' => '提现成功');
  425. }
  426. echo json_encode($result);
  427. die();
  428. }
  429. /**
  430. 提现记录
  431. **/
  432. public function tixian_record()
  433. {
  434. $_GPC = I('request.');
  435. $token = $_GPC['token'];
  436. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  437. $member_id = $weprogram_token['member_id'];
  438. if( empty($member_id) )
  439. {
  440. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  441. die();
  442. }
  443. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  444. if( $orderdistribution_id <= 0 )
  445. {
  446. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  447. die();
  448. }
  449. $per_page = 10;
  450. $page = isset($_GPC['page']) ? $_GPC['page']:1;
  451. $offset = ($page - 1) * $per_page;
  452. $list = array();
  453. $list = M('lionfish_comshop_orderdistribution_tixian_order')->where( array('member_id' =>$member_id ) )->order('addtime desc')->limit($offset,$per_page )->select();
  454. foreach($list as $key => $val)
  455. {
  456. $val['addtime'] = date('Y-m-d H:i', $val['addtime']);
  457. $list[$key] = $val;
  458. }
  459. if( !empty($list) )
  460. {
  461. echo json_encode( array('code' =>0, 'data'=>$list) );
  462. die();
  463. }else{
  464. echo json_encode( array('code' => 1) );
  465. die();
  466. }
  467. }
  468. //end
  469. /**
  470. 确认抢单
  471. **/
  472. public function rob_distribution_order()
  473. {
  474. $_GPC = I('request.');
  475. $token = $_GPC['token'];
  476. $order_id = $_GPC['order_id'];
  477. $ps_lon = $_GPC['ps_lon'];//配送员经度
  478. $ps_lat = $_GPC['ps_lat'];//配送员纬度
  479. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  480. $member_id = $weprogram_token['member_id'];
  481. if( empty($member_id) )
  482. {
  483. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  484. die();
  485. }
  486. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  487. if( $orderdistribution_id <= 0 )
  488. {
  489. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  490. die();
  491. }
  492. $order_info = M('lionfish_comshop_order')->where(array('order_id' => $order_id ) )->find();
  493. $localtown_grabbing_distance = D('Home/Front')->get_config_by_name('localtown_grabbing_distance');
  494. if($order_info['store_id'] > 0){
  495. $localtown_grabbing_distance = D('Home/Front')->get_supply_config_by_name('localtown_grabbing_distance',$order_info['store_id']);
  496. }
  497. if(!empty($localtown_grabbing_distance) && is_numeric($localtown_grabbing_distance)){
  498. $distribution_order = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  499. // 计算配送员距离
  500. //$distince = D('Seller/Communityhead')->GetDistance($ps_lon,$ps_lat, $distribution_order['member_lon'], $distribution_order['member_lat']);
  501. $distince = D('Seller/Communityhead')->GetDistance($ps_lat,$ps_lon, $distribution_order['shop_lon'], $distribution_order['shop_lat']);
  502. if($distince > $localtown_grabbing_distance){
  503. $msg = "距离店铺地址还有".$distince."米,不能确认抢单,".$localtown_grabbing_distance."米内,可以确认抢单";
  504. echo json_encode( array('code' => 3, 'msg' => $msg ) );
  505. die();
  506. }
  507. }
  508. $res = D('Home/LocaltownDelivery')->distribution_get_order( $orderdistribution_id , $order_id );
  509. if( !$res )
  510. {
  511. echo json_encode( array('code' => 2, 'msg' => '抢单失败') );
  512. die();
  513. }else {
  514. echo json_encode( array('code' => 1 , 'msg' => '抢单成功' ) );
  515. die();
  516. }
  517. }
  518. /**
  519. 确认取货
  520. **/
  521. public function distribution_deliverying_order()
  522. {
  523. $_GPC = I('request.');
  524. $token = $_GPC['token'];
  525. $order_id = $_GPC['order_id'];
  526. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  527. $member_id = $weprogram_token['member_id'];
  528. if( empty($member_id) )
  529. {
  530. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  531. die();
  532. }
  533. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  534. if( $orderdistribution_id <= 0 )
  535. {
  536. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  537. die();
  538. }
  539. $res = D('Home/LocaltownDelivery')->distribution_deliverying_order( $order_id );
  540. if( !$res )
  541. {
  542. echo json_encode( array('code' => 2, 'msg' => '配送失败') );
  543. die();
  544. }else {
  545. echo json_encode( array('code' => 1 , 'msg' => '配送成功' ) );
  546. die();
  547. }
  548. }
  549. /**
  550. 确认送达
  551. **/
  552. public function distribution_arrived_order( )
  553. {
  554. $_GPC = I('request.');
  555. $token = $_GPC['token'];
  556. $order_id = $_GPC['order_id'];
  557. $ps_lon = $_GPC['ps_lon'];//配送员经度
  558. $ps_lat = $_GPC['ps_lat'];//配送员纬度
  559. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  560. $member_id = $weprogram_token['member_id'];
  561. if( empty($member_id) )
  562. {
  563. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  564. die();
  565. }
  566. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  567. if( $orderdistribution_id <= 0 )
  568. {
  569. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  570. die();
  571. }
  572. $order_supplyid = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->find();
  573. if($order_supplyid['supply_id'] > 0 ){
  574. $localtown_confirm_delivery_distance = D('Home/Front')->get_supply_config_by_name('localtown_confirm_delivery_distance',$order_supplyid['supply_id']);
  575. if(!empty($localtown_confirm_delivery_distance) && is_numeric($localtown_confirm_delivery_distance)){
  576. $distribution_order = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  577. // 计算配送员距离
  578. //$distince = D('Seller/Communityhead')->GetDistance($ps_lon,$ps_lat, $distribution_order['member_lon'], $distribution_order['member_lat']);
  579. $distince = D('Seller/Communityhead')->GetDistance($ps_lat,$ps_lon, $distribution_order['member_lon'], $distribution_order['member_lat']);
  580. if($distince > $localtown_confirm_delivery_distance){
  581. $msg = "距离用户收货地址还有".$distince."米,不能完成订单,".$localtown_confirm_delivery_distance."米内,可以完成订单";
  582. echo json_encode( array('code' => 3, 'msg' => $msg ) );
  583. die();
  584. }
  585. }
  586. }else{
  587. $localtown_confirm_delivery_distance = D('Home/Front')->get_config_by_name('localtown_confirm_delivery_distance');
  588. if(!empty($localtown_confirm_delivery_distance) && is_numeric($localtown_confirm_delivery_distance)){
  589. $distribution_order = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  590. // 计算配送员距离
  591. //$distince = D('Seller/Communityhead')->GetDistance($ps_lon,$ps_lat, $distribution_order['member_lon'], $distribution_order['member_lat']);
  592. $distince = D('Seller/Communityhead')->GetDistance($ps_lat,$ps_lon, $distribution_order['member_lon'], $distribution_order['member_lat']);
  593. if($distince > $localtown_confirm_delivery_distance){
  594. $msg = "距离用户收货地址还有".$distince."米,不能完成订单,".$localtown_confirm_delivery_distance."米内,可以完成订单";
  595. echo json_encode( array('code' => 3, 'msg' => $msg ) );
  596. die();
  597. }
  598. }
  599. }
  600. $res = D('Home/LocaltownDelivery')->distribution_arrived_order( $order_id , 1);
  601. if( !$res )
  602. {
  603. echo json_encode( array('code' => 2, 'msg' => '配送失败') );
  604. die();
  605. }else {
  606. echo json_encode( array('code' => 1 , 'msg' => '配送成功' ) );
  607. die();
  608. }
  609. }
  610. /**
  611. * 修改配送员语音通知状态
  612. */
  613. public function change_distribution_notice(){
  614. $_GPC = I('request.');
  615. $token = $_GPC['token'];
  616. $is_new_notice = $_GPC['is_new_notice'];
  617. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  618. $member_id = $weprogram_token['member_id'];
  619. if( empty($member_id) )
  620. {
  621. echo json_encode( array('code' =>0,'msg' =>'未登录') );
  622. die();
  623. }
  624. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  625. if( $orderdistribution_id <= 0 )
  626. {
  627. echo json_encode( array('code' => 0, 'msg' => '不是配送员' ) );
  628. die();
  629. }
  630. $res = M('lionfish_comshop_orderdistribution')->where( array('member_id' => $member_id) )->save(array('is_new_notice'=>$is_new_notice));
  631. if($res !== false){
  632. echo json_encode( array('code' => 1, 'msg' => '设置成功' ) );
  633. die();
  634. }else{
  635. echo json_encode( array('code' => 0, 'msg' => '设置失败' ) );
  636. die();
  637. }
  638. }
  639. }