User.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\index\controller;
  15. use library\Controller;
  16. use think\Db;
  17. use app\index\controller\Api;
  18. /**
  19. * 用户信息
  20. * Class User
  21. * @package app\index\controller
  22. */
  23. class User extends Api
  24. {
  25. /**
  26. * 施工照片
  27. */
  28. public function userImage()
  29. {
  30. $user = $this->geiUserInfo();
  31. $data = Db::name('user_image')->where('uid',$user['id'])->order('create_time')->select();
  32. if (!$data) return $this->success('',[]);
  33. foreach ($data as &$v) {
  34. $v['image'] = explode('|',$v['image']);
  35. }
  36. return $this->success('',$data);
  37. }
  38. /**
  39. * 线上预约
  40. * name 姓名
  41. * phone 手机号
  42. * address 城市
  43. * address_info 详细地址
  44. */
  45. public function appinotment()
  46. {
  47. $data = $this->request->post();
  48. if (!isset($data['name']) || empty($data['name'])) return $this->error('请输入姓名');
  49. if (!isset($data['phone']) || empty($data['phone'])) return $this->error('请输入手机号');
  50. if (!isset($data['address']) || empty($data['address'])) return $this->error('请输入所造地区');
  51. if (!isset($data['address_info']) || empty($data['address_info'])) return $this->error('请输入详细地址');
  52. if(strlen($data['name'])<3 || strlen($data['name'])>12) return $this->error('姓名长度为3-12位');
  53. if(!preg_match("/^1[34578]\d{9}$/", $data['phone'])) return $this->error('手机号格式不正确');
  54. $user = $this->geiUserInfo();
  55. $data['uid'] = $user['id'];
  56. $data['number'] = date('Y',time()).date('m',time()).date('d',time()).date('H',time()).date('i',time()).rand(100000,999999);
  57. $data['create_time'] = date('Y-m-d H:i',time());
  58. $save = Db::name('user_appointment')->insert($data);
  59. if ($save) {
  60. return $this->success('提交成功');
  61. } else {
  62. return $this->error('提交失败');
  63. }
  64. }
  65. /**
  66. * 跟进反馈
  67. * content 文字
  68. * image 图片
  69. */
  70. public function feedback()
  71. {
  72. $data = $this->request->post();
  73. if (!isset($data['content']) && empty($data['image'])) return $this->error('请输入有效信息');
  74. $user = $this->geiUserInfo();
  75. $data['uid'] = $user['id'];
  76. $data['create_time'] = date('Y-m-d H:i',time());
  77. $paths = json_decode($data['image'],true);
  78. if (!empty($paths)) {
  79. $str = '';
  80. foreach ($paths as $v) {
  81. $image =json_encode($v, JSON_FORCE_OBJECT);
  82. $imageName = "25220_" . date("His", time()) . "_" . rand(1111, 9999) . '.png';
  83. if (strstr($image, ",")) {
  84. $image = explode(',', $image);
  85. $image = $image[1];
  86. }
  87. $path = "uploads/images/" . date("Ymd", time());
  88. if (!is_dir($path)) { //判断目录是否存在 不存在就创建
  89. mkdir($path, 0777, true);
  90. }
  91. $imageSrc = $path . "/" . $imageName; //图片名字
  92. $r = file_put_contents($this->app->getRootPath() . "public/" . $imageSrc, base64_decode($image));//返回的是字节数
  93. if ($r) {
  94. $str = $str . 'http://degao.hdlkeji.com/' .$imageSrc . '|';
  95. }
  96. }
  97. $data['image'] = $str;
  98. }
  99. $save = Db::name('user_feedback')->insert($data);
  100. if ($save) {
  101. return $this->success('提交成功');
  102. } else {
  103. return $this->error('提交失败');
  104. }
  105. }
  106. /**
  107. * 施工订单
  108. * type 1进行中2已完成
  109. */
  110. public function order()
  111. {
  112. $type = $this->request->get('type');
  113. $user = $this->geiUserInfo();
  114. $data = Db::name('user_appointment')->where('status',$type)->where('uid',$user['id'])->order('create_time')->select();
  115. $res = Db::name('user_weixiu_baobei')->where('status',$type)->where('uid',$user['id'])->order('create_time')->select();
  116. $datas = array_merge($data,$res);
  117. # 按距离降序排序
  118. $a = self::arraySort($datas, 'create_time', SORT_DESC);
  119. // print_r($a);die;
  120. // # 按money升序排序
  121. // $b = arraySort($data, 'money', SORT_ASC);
  122. // print_r($b);
  123. return $this->success('',$a);
  124. }
  125. /**
  126. * 二维数组根据某个字段排序
  127. * @param array $array 要排序的数组
  128. * @param string $keys 要排序的键字段
  129. * @param string $sort 排序类型 SORT_ASC SORT_DESC
  130. * @return array 排序后的数组
  131. */
  132. function arraySort($array, $keys, $sort = SORT_DESC) {
  133. $keysValue = [];
  134. foreach ($array as $k => $v) {
  135. $keysValue[$k] = $v[$keys];
  136. }
  137. array_multisort($keysValue, $sort, $array);
  138. return $array;
  139. }
  140. /**
  141. * 维修和报备
  142. * name 姓名
  143. * phone 手机号
  144. * address 城市
  145. * address_info 详细地址
  146. * type 1维修2报备
  147. */
  148. public function weixiuBaobei()
  149. {
  150. $data = $this->request->post();
  151. if (!isset($data['name']) || empty($data['name'])) return $this->error('请输入姓名');
  152. if (!isset($data['phone']) || empty($data['phone'])) return $this->error('请输入手机号');
  153. if (!isset($data['address']) || empty($data['address'])) return $this->error('请输入所造地区');
  154. if (!isset($data['address_info']) || empty($data['address_info'])) return $this->error('请输入详细地址');
  155. if(strlen($data['name'])<3 || strlen($data['name'])>12) return $this->error('姓名长度为3-12位');
  156. if(!preg_match("/^1[34578]\d{9}$/", $data['phone'])) return $this->error('手机号格式不正确');
  157. $user = $this->geiUserInfo();
  158. $data['uid'] = $user['id'];
  159. $data['number'] = date('Y',time()).date('m',time()).date('d',time()).date('H',time()).date('i',time()).rand(100000,999999);
  160. $data['create_time'] = date('Y-m-d H:i',time());
  161. $save = Db::name('user_weixiu_baobei')->insert($data);
  162. if ($save) {
  163. return $this->success('提交成功');
  164. } else {
  165. return $this->error('提交失败');
  166. }
  167. }
  168. /**
  169. * 积分明细
  170. */
  171. public function integral()
  172. {
  173. $user = $this->geiUserInfo();
  174. $data = Db::name('user_integral_history')->where('uid',$user['id'])->order('create_time')->select();
  175. return $this->success('',$data);
  176. }
  177. /**
  178. * 服务订单
  179. */
  180. public function fuwuOrder()
  181. {
  182. $user = $this->geiUserInfo();
  183. $data = Db::name('user_order')->where('uid',$user['id'])->order('create_time')->select();
  184. return $this->success('',$data);
  185. }
  186. /**
  187. * 用户信息
  188. */
  189. public function userInfo()
  190. {
  191. $user = $this->geiUserInfo();
  192. return $this->success('',$user);
  193. }
  194. }