123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-09
- * Time: 9:04
- */
- namespace api\js\controller;
- use api\js\model\DistributorLogModel;
- use api\js\model\DistributorModel;
- use api\js\model\JsModel;
- use api\js\model\JsTimeModel;
- use api\js\model\UserDiscountModel;
- use api\js\model\UserModel;
- use api\js\model\UserTxModel;
- use cmf\controller\RestUserBaseController;
- use think\Db;
- use think\Validate;
- class UserController extends RestUserBaseController
- {
- /**
- * 注销用户账户
- *
- * @param [type] $mobile
- * @param [type] $product
- * @return void
- */
- public function destroy()
- {
- $user_id = $this->getUserId();
- $info = UserModel::get($user_id);
- $res = $info->delete();
- $this->success('注销成功', $res);
- }
- /**
- * 用户信息
- */
- public function getInfo()
- {
- $user_id = $this->getUserId();
- $info = UserModel::get($user_id);
- $info->openid = Db::name('third_party_user')->where('user_id', $user_id)->value('openid');
- $info->js;
- if ($info['user_type'] == 3) {
- $info['js']['is_work'] = 0;
- if ($info['js']->js_time) {
- $week = date('w', time());
- if (in_array($week, $info['js']->js_time->weeks)) {
- foreach ($info['js']->js_time->times as $vo) {
- if (strtotime($vo['js_end_time']) >= strtotime(date('H:i'))) {
- //在此处判断一下是否已经接单
- $is_work = Db::name('js_order')->where('jiedan_js_id', $info['js']['id'])->where('status', 6)->find();
- if (empty($is_work)) {
- $info['js']['is_work'] = 1;
- } else {
- $info['js']['is_work'] = 2;
- }
- }
- }
- }
- unset($info['js']->js_time);
- }
- }
- $info->is_agency = 0;
- if ($info->agency_id) {
- $info->is_agency = 1;
- $info->agency_id = 1;
- } else {
- $info->agency_id = 0;
- }
- $info->distributor_status = DistributorLogModel::where('user_id', $user_id)->value('chuli_status');
- $info->fenxiaoshang = DistributorModel::get($info->distributor_id)['name'];
- unset($info['user_pass']);
- $this->success('ok', $info);
- }
- /**
- * 申请成为技师
- */
- public function applyJsPost()
- {
- $user_id = $this->getUserId();
- $user_info = UserModel::get($user_id);
- $user_type = $user_info['user_type'];
- if ($user_type != 3) {
- $this->error('请先去师傅端注册!');
- }
- $data['user_id'] = $user_id;
- $data['name'] = $this->request->param('name');
- $phone = $this->request->param('phone');
- $data['phone'] = $phone ?: $user_info['mobile'];
- // if (!$data['phone']) {
- // $this->error('请填写联系电话不可为空!');
- // }
- $data['is_real_time'] = $this->request->param('is_real_time');
- $data['is_make'] = $this->request->param('is_make');
- $data['jianjie'] = $this->request->param('jianjie');
- $data['sex'] = $this->request->param('sex');
- $data['apply_num'] = 1;
- $data['identity'] = $this->request->param('identity/a');
- $data['certificates'] = $this->request->param('certificates/a');
- $data['pictures'] = $this->request->param('pictures/a');
- $work = $this->request->param('work/a');
- if (isset($work)) {
- $data['work'] = $work;
- }
- $JsModel = new JsModel();
- // $js_id = $JsModel::where('phone',$data['phone'])->value('id');
- // if($js_id){
- // $this->error('此号码已认证,请到我的设置中修改信息!');
- // }
- $info = $JsModel::where('user_id', $user_id)->find();
- $JsTimeModel = new JsTimeModel();
- if ($info) {
- $js_time['js_id'] = $info['id'];
- $js_time_info = Db::name('js_time')->where('js_id', $js_time['js_id'])->find();
- if (!$js_time_info) {
- $js_time['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
- $js_time['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
- $JsTimeModel->allowField(true)->isUpdate(false)->save($js_time);
- }
- $data['js_status'] = 0;
- $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $info['id']]);
- $this->success('修改成功');
- } else {
- $JsModel->applyJsPost($data);
- $js_time['js_id'] = $JsModel->id;
- $js_time_info = Db::name('js_time')->where('js_id', $js_time['js_id'])->find();
- if (!$js_time_info) {
- $js_time['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
- $js_time['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
- $JsTimeModel->allowField(true)->isUpdate(false)->save($js_time);
- }
- $this->success('申请成功');
- }
- }
- /**
- * 申请项目
- */
- public function applyProjectPost()
- {
- $user_id = $this->getUserId();
- $project_id = $this->request->param('project_id');
- if (!$project_id) {
- $this->error('缺少project_id参数!');
- }
- $user_type = UserModel::get($user_id)['user_type'];
- if ($user_type != 3) {
- $this->error('请先去师傅端注册!');
- }
- $JsModel = new JsModel();
- $js_id = $JsModel::where('user_id', $user_id)->value('id');
- $res = $JsModel->applyProjectPost($js_id, $project_id);
- if ($res) {
- $this->success('申请成功');
- } else {
- $this->error('无需重复申请!');
- }
- }
- public function getDiscount()
- {
- $where = [];
- $status = $this->request->param('status');
- if ($status || $status === '0') {
- $where['status'] = $status;
- }
- $where['user_id'] = $this->getUserId();
- $UserDiscountModel = new UserDiscountModel();
- $list = $UserDiscountModel->getList($where);
- $this->success('ok', $list);
- }
- /**
- * 用户修改信息
- */
- public function editInfo()
- {
- $user_id = $this->getUserId();
- $data['avatar'] = $this->request->param('avatar');
- $data['user_nickname'] = $this->request->param('user_nickname');
- $UserMolde = new UserModel();
- $UserMolde->allowField(true)->isUpdate(true)->save($data, ['id' => $user_id]);
- // $JsModel = new JsModel();
- // $JsModel->allowField(true)->isUpdate(true)->save($data,['user_id'=>$user_id]);
- $this->success('修改成功');
- }
- public function addIdea()
- {
- $data['user_id'] = $this->getUserId();
- $data['idea'] = $this->request->param('idea');
- $data['add_time'] = time();
- Db::name('idea')->insert($data);
- $this->success('提交成功');
- }
- public function getxiaji()
- {
- $page = $this->request->param('page', 1);
- $type = $this->request->param('type', 1);
- $userModel = new UserModel();
- $user_id = $this->getUserId();
- $fied = 'parent_id';
- if ($type == 2) {
- $fied = 'parent_id1';
- }
- $list = $userModel::where($fied, $user_id)->order('id', 'desc')->page($page, 20)->field('id,mobile,user_nickname,create_time')->select()->each(function ($list) {
- $list['mobile'] = preg_replace("/(\d{3})\d{4}(\d{4})/", "\$1****\$2", $list['mobile']);
- return $list;
- });
- $this->success('ok', $list);
- }
- public function getMoneyLog()
- {
- $page = $this->request->param('page', 1);
- $list = Db::name('user_money_log')->where('user_id', $this->getUserId())->order('id', 'desc')->page($page, 20)->select();
- $this->success('ok', $list);
- }
- /**
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- *获取二维码
- */
- public function geterweima()
- {
- $user_id = $this->getUserId();
- $erweima = UserModel::get($user_id)['erweima'];
- $referral = UserModel::get($user_id)['referral'];
- $value = 'http://' . $_SERVER['SERVER_NAME'] . '/h5/#/pages/zhuce/zhuce?yqm=' . $referral;
- if (!$erweima) {
- $res = qeCode($value, $this->request->controller(), $user_id);
- UserModel::where('id', $user_id)->update(['erweima' => $res]);
- $this->success('ok', ['erweima' => cmf_get_image_preview_url($res), 'url' => $value, 'referral' => $referral]);
- } else {
- $this->success('ok', ['erweima' => cmf_get_image_preview_url($erweima), 'url' => $value, 'referral' => $referral]);
- }
- }
- /**
- * @throws \think\Exception
- * 提现
- */
- public function addTx()
- {
- $data['user_id'] = $this->getUserId();
- $data['tx_type'] = $this->request->param('tx_type');
- $data['money'] = $this->request->param('money');
- $data['zfb_name'] = $this->request->param('zfb_name');
- $data['zfb_action'] = $this->request->param('zfb_action');
- $data['order_sn'] = cmf_get_order_sn();
- $user_balance = UserModel::get($this->getUserId())['balance'];
- if ($data['tx_type'] == 1) {
- $wx_openid = Db::name('third_party_user')->where('user_id', $data['user_id'])->where('union_id', '微信平台')->value('openid');
- if (!$wx_openid) {
- $this->error('请先绑定wx_openid!');
- }
- } else {
- $validate = new Validate([
- 'zfb_name' => 'require',
- 'zfb_action' => 'require',
- ]);
- $validate->message([
- 'zfb_name.require' => '支付宝姓名不可为空!',
- 'zfb_action.require' => '支付宝账号不可为空!',
- ]);
- if (!$validate->check($data)) {
- $this->error($validate->getError());
- }
- }
- if ($data['money'] > $user_balance) {
- $this->error('余额不足!');
- }
- if ($data['money'] < 0.01) {
- $this->error('提现余额不可小于0.01!');
- }
- UserModel::where('id', $data['user_id'])->setDec('balance', $data['money']);
- $UserTxModel = new UserTxModel();
- $UserTxModel->allowField(true)->isUpdate(false)->save($data);
- $log['user_id'] = $data['user_id'];
- $log['money'] = -$data['money'];
- $log['yue'] = $user_balance - $data['money'];
- $log['type'] = 99;
- $log['remark'] = '余额提现';
- $log['add_time'] = time();
- $log['obj_id'] = $UserTxModel->id;
- Db::name('user_money_log')->insert($log);
- $this->success('申请成功');
- }
- /**
- * 申请代理
- */
- public function agencyapply()
- {
- $data['name'] = $this->request->param('name');
- $data['mobile'] = $this->request->param('mobile');
- $data['district'] = $this->request->param('district');
- $data['add_time'] = time();
- $data['user_id'] = $this->getUserId();
- Db::name('user_apply_agency')->insert($data);
- $this->success('ok', '申请成功');
- }
- }
|