LocaltownController.class.php 29 KB

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