123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\index\controller;
- use library\Controller;
- use think\Db;
- use app\index\controller\Api;
- /**
- * 用户信息
- * Class User
- * @package app\index\controller
- */
- class User extends Api
- {
- /**
- * 施工照片
- */
- public function userImage()
- {
- $user = $this->geiUserInfo();
- $data = Db::name('user_image')->where('uid',$user['id'])->order('create_time')->select();
- if (!$data) return $this->success('',[]);
- foreach ($data as &$v) {
- $v['image'] = explode('|',$v['image']);
- }
- return $this->success('',$data);
- }
- /**
- * 线上预约
- * name 姓名
- * phone 手机号
- * address 城市
- * address_info 详细地址
- */
- public function appinotment()
- {
- $data = $this->request->post();
- if (!isset($data['name']) || empty($data['name'])) return $this->error('请输入姓名');
- if (!isset($data['phone']) || empty($data['phone'])) return $this->error('请输入手机号');
- if (!isset($data['address']) || empty($data['address'])) return $this->error('请输入所造地区');
- if (!isset($data['address_info']) || empty($data['address_info'])) return $this->error('请输入详细地址');
- if(strlen($data['name'])<3 || strlen($data['name'])>12) return $this->error('姓名长度为3-12位');
- if(!preg_match("/^1[34578]\d{9}$/", $data['phone'])) return $this->error('手机号格式不正确');
- $user = $this->geiUserInfo();
- $data['uid'] = $user['id'];
- $data['number'] = date('Y',time()).date('m',time()).date('d',time()).date('H',time()).date('i',time()).rand(100000,999999);
- $data['create_time'] = date('Y-m-d H:i',time());
- $save = Db::name('user_appointment')->insert($data);
- if ($save) {
- return $this->success('提交成功');
- } else {
- return $this->error('提交失败');
- }
- }
- /**
- * 跟进反馈
- * content 文字
- * image 图片
- */
- public function feedback()
- {
- $data = $this->request->post();
- if (!isset($data['content']) && empty($data['image'])) return $this->error('请输入有效信息');
- $user = $this->geiUserInfo();
- $data['uid'] = $user['id'];
- $data['create_time'] = date('Y-m-d H:i',time());
- $paths = json_decode($data['image'],true);
- if (!empty($paths)) {
- $str = '';
- foreach ($paths as $v) {
- $image =json_encode($v, JSON_FORCE_OBJECT);
- $imageName = "25220_" . date("His", time()) . "_" . rand(1111, 9999) . '.png';
- if (strstr($image, ",")) {
- $image = explode(',', $image);
- $image = $image[1];
- }
- $path = "uploads/images/" . date("Ymd", time());
- if (!is_dir($path)) { //判断目录是否存在 不存在就创建
- mkdir($path, 0777, true);
- }
- $imageSrc = $path . "/" . $imageName; //图片名字
- $r = file_put_contents($this->app->getRootPath() . "public/" . $imageSrc, base64_decode($image));//返回的是字节数
- if ($r) {
- $str = $str . 'http://degao.hdlkeji.com/' .$imageSrc . '|';
- }
- }
- $data['image'] = $str;
- }
- $save = Db::name('user_feedback')->insert($data);
- if ($save) {
- return $this->success('提交成功');
- } else {
- return $this->error('提交失败');
- }
- }
- /**
- * 施工订单
- * type 1进行中2已完成
- */
- public function order()
- {
- $type = $this->request->get('type');
- $user = $this->geiUserInfo();
- $data = Db::name('user_appointment')->where('status',$type)->where('uid',$user['id'])->order('create_time')->select();
- $res = Db::name('user_weixiu_baobei')->where('status',$type)->where('uid',$user['id'])->order('create_time')->select();
- $datas = array_merge($data,$res);
- # 按距离降序排序
- $a = self::arraySort($datas, 'create_time', SORT_DESC);
- // print_r($a);die;
- // # 按money升序排序
- // $b = arraySort($data, 'money', SORT_ASC);
- // print_r($b);
- return $this->success('',$a);
- }
- /**
- * 二维数组根据某个字段排序
- * @param array $array 要排序的数组
- * @param string $keys 要排序的键字段
- * @param string $sort 排序类型 SORT_ASC SORT_DESC
- * @return array 排序后的数组
- */
- function arraySort($array, $keys, $sort = SORT_DESC) {
- $keysValue = [];
- foreach ($array as $k => $v) {
- $keysValue[$k] = $v[$keys];
- }
- array_multisort($keysValue, $sort, $array);
- return $array;
- }
- /**
- * 维修和报备
- * name 姓名
- * phone 手机号
- * address 城市
- * address_info 详细地址
- * type 1维修2报备
- */
- public function weixiuBaobei()
- {
- $data = $this->request->post();
- if (!isset($data['name']) || empty($data['name'])) return $this->error('请输入姓名');
- if (!isset($data['phone']) || empty($data['phone'])) return $this->error('请输入手机号');
- if (!isset($data['address']) || empty($data['address'])) return $this->error('请输入所造地区');
- if (!isset($data['address_info']) || empty($data['address_info'])) return $this->error('请输入详细地址');
- if(strlen($data['name'])<3 || strlen($data['name'])>12) return $this->error('姓名长度为3-12位');
- if(!preg_match("/^1[34578]\d{9}$/", $data['phone'])) return $this->error('手机号格式不正确');
- $user = $this->geiUserInfo();
- $data['uid'] = $user['id'];
- $data['number'] = date('Y',time()).date('m',time()).date('d',time()).date('H',time()).date('i',time()).rand(100000,999999);
- $data['create_time'] = date('Y-m-d H:i',time());
- $save = Db::name('user_weixiu_baobei')->insert($data);
- if ($save) {
- return $this->success('提交成功');
- } else {
- return $this->error('提交失败');
- }
- }
- /**
- * 积分明细
- */
- public function integral()
- {
- $user = $this->geiUserInfo();
-
- $data = Db::name('user_integral_history')->where('uid',$user['id'])->order('create_time')->select();
- return $this->success('',$data);
- }
-
- /**
- * 服务订单
- */
- public function fuwuOrder()
- {
- $user = $this->geiUserInfo();
- $data = Db::name('user_order')->where('uid',$user['id'])->order('create_time')->select();
- foreach ($data as &$v) {
- $v['images'] = explode('|',$v['image']);
- }
- return $this->success('',$data);
- }
-
- /**
- * 用户信息
- */
- public function userInfo()
- {
- $user = $this->geiUserInfo();
- return $this->success('',$user);
- }
- }
|