Agent.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\mainapp\controller;
  3. use think\facade\Session;
  4. use app\mainapp\BaseController;
  5. use app\common\model\Param as ParamModel;
  6. use app\common\model\Agent as AgentModel;
  7. use app\common\model\AgentForm as AgentFormModel;
  8. class Agent extends BaseController
  9. {
  10. // 申请代理门店
  11. public function pageForm()
  12. {
  13. $param = ParamModel::where(1)->find();
  14. page_result(0, "", array(
  15. 'param' => $param
  16. ));
  17. }
  18. public function regAgent()
  19. {
  20. $realname = input('realname/s', "");
  21. $mobile = input('mobile/s', "");
  22. $address = input('address/s', "");
  23. $idcard = input('idcard/s', "");
  24. $recommender = input('recommender/s', "");
  25. if ( empty($realname) || empty($mobile) || empty($address) || empty($idcard) ){
  26. page_result(1, "姓名、手机号、当前住址、身份证号均不能为空。");
  27. }
  28. $form = new AgentFormModel;
  29. $form->save([
  30. 'realname' => $realname,
  31. 'mobile' => $mobile,
  32. 'address' => $address,
  33. 'idcard' => $idcard,
  34. 'recommender' => $recommender,
  35. 'status' => 1,
  36. 'remark' => "",
  37. 'createtime' => time()
  38. ]);
  39. page_result(0, "", array());
  40. }
  41. // 代理门店详情
  42. public function getAgent()
  43. {
  44. $agentid = input('agentid/d', 0);
  45. $agent = AgentModel::where('id','=',$agentid)
  46. // ->field("*, ROUND( (2 * $EARTH* ASIN(SQRT(POW(SIN($PI*(".$lat."-latitude)/360),2)+COS($PI*".$lat."/180)* COS(latitude * $PI/180)*POW(SIN($PI*(".$lng."-longitude)/360),2))))/1000, 2 ) as juli")
  47. ->findOrEmpty();
  48. if ($agent->isEmpty()){
  49. page_result(1, "代理门店信息不存在");
  50. }
  51. page_result(0, "", array(
  52. 'agent' => $agent
  53. ));
  54. }
  55. // 代理门店列表
  56. public function listAgent()
  57. {
  58. $psize = input('psize/d', 5);
  59. $map[] = ['status','=',1];
  60. $lng = input('lng/f', 0);
  61. $lat = input('lat/f', 0);
  62. $plist = AgentModel::where($map)
  63. ->field("*, ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*PI()/180-latitude*PI()/180)/2),2)+COS($lat*PI()/180)*COS(latitude*PI()/180)*POW(SIN(($lng*PI()/180-longitude*PI()/180)/2),2))), 2) as juli")
  64. ->order(['juli'=>'asc','priority'=>'desc','id'=>'desc'])->limit($psize)->select();
  65. page_result(0, "", array(
  66. 'plist' => $plist,
  67. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more'
  68. ));
  69. }
  70. }