| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\wap\controller;
- use Api\Express;
- use app\wap\model\special\SpecialRecord;
- use app\wap\model\special\SpecialLog;
- use app\wap\model\special\SpecialBuy;
- use app\wap\model\special\SpecialSource;
- use app\wap\model\special\SpecialRelation;
- use app\admin\model\questions\Relation;
- use app\wap\model\user\SmsCode;
- use app\wap\model\store\StoreOrderCartInfo;
- use app\wap\model\recommend\Recommend;
- use app\wap\model\store\StoreOrder;
- use app\wap\model\user\PhoneUser;
- use app\wap\model\user\User;
- use app\wap\model\user\UserBill;
- use app\wap\model\user\UserExtract;
- use app\wap\model\user\UserAddress;
- use app\wap\model\user\UserSign;
- use service\GroupDataService;
- use service\JsonService;
- use service\SystemConfigService;
- use service\UtilService;
- use think\Cookie;
- use think\Request;
- use think\Session;
- use think\Url;
- /**my 控制器
- * Class My
- * @package app\wap\controller
- */
- class My extends AuthController
- {
- /*
- * 白名单
- * */
- public static function WhiteList()
- {
- return [
- 'index',
- 'about_us',
- 'getPersonalCenterMenu',
- 'questionModule'
- ];
- }
- /**
- * 退出手机号码登录
- */
- public function logout()
- {
- Cookie::delete('__login_phone');
- Session::delete('__login_phone_num' . $this->uid, 'wap');
- Session::delete('loginUid', 'wap');
- return JsonService::successful('已退出登录');
- }
- /**
- * 获取获取个人中心菜单
- */
- public function getPersonalCenterMenu()
- {
- $store_brokerage_statu = SystemConfigService::get('store_brokerage_statu');
- if ($store_brokerage_statu == 1) {
- if (isset($this->userInfo['is_promoter'])) $is_statu = $this->userInfo['is_promoter'] > 0 ? 1 : 0;
- else $is_statu = 0;
- } else if ($store_brokerage_statu == 2) {
- $is_statu = 1;
- }
- $is_write_off = isset($this->userInfo['is_write_off']) ? $this->userInfo['is_write_off'] : 0;
- $business = isset($this->userInfo['business']) ? $this->userInfo['business'] : 0;
- return JsonService::successful(Recommend::getPersonalCenterMenuList($is_statu, $is_write_off, $business, $this->uid));
- }
- /**
- * 题库模块
- */
- public function questionModule()
- {
- $question = GroupDataService::getData('question_bank_module', 2);
- return JsonService::successful($question);
- }
- /**我的赠送
- * @return mixed
- */
- public function my_gift()
- {
- return $this->fetch();
- }
- /**我的报名
- * @return mixed
- */
- public function sign_list()
- {
- return $this->fetch();
- }
- /**获取核销订单信息
- * @param int $type
- * @param string $order_id
- * @return mixed|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function sign_order($type = 2, $order_id = '')
- {
- if ($type == 2 && !$this->userInfo['is_write_off']) return $this->failed('您没有权限!');
- $this->assign(['type' => $type, 'order_id' => $order_id]);
- return $this->fetch();
- }
- /**报名详情
- * @param string $order_id
- * @return mixed|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function sign_my_order($order_id = '')
- {
- $this->assign(['order_id' => $order_id]);
- return $this->fetch('order_verify');
- }
- /**我的信息
- * @return mixed
- */
- public function user_info()
- {
- return $this->fetch();
- }
- public function verify_activity()
- {
- return $this->fetch();
- }
- /**
- * 手机号验证
- */
- public function validate_code()
- {
- list($phone, $code,) = UtilService::getMore([
- ['phone', ''],
- ['code', ''],
- ], $this->request, true);
- if (!$phone) return JsonService::fail('请输入手机号码');
- if (!$code) return JsonService::fail('请输入验证码');
- $code = md5('is_phone_code' . $code);
- if (!SmsCode::CheckCode($phone, $code)) return JsonService::fail('验证码验证失败');
- SmsCode::setCodeInvalid($phone, $code);
- return JsonService::successful('验证成功');
- }
- /**
- * 信息保存
- */
- public function save_user_info()
- {
- $data = UtilService::postMore([
- ['avatar', ''],
- ['nickname', ''],
- ['realname', ''],
- ['comment', ''],
- ['grade_id', 0]
- ], $this->request);
- if ($data['nickname'] != strip_tags($data['nickname'])) {
- $data['nickname'] = htmlspecialchars($data['nickname']);
- }
- if (!$data['nickname']) return JsonService::fail('用户昵称不能为空');
- if (User::update($data, ['uid' => $this->uid]))
- return JsonService::successful('保存成功');
- else
- return JsonService::fail('保存失败');
- }
- /**
- * 保存手机号码
- * @return mixed|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function save_phone()
- {
- if ($this->request->isAjax()) {
- list($phone, $code, $type) = UtilService::getMore([
- ['phone', ''],
- ['code', ''],
- ['type', 0],
- ], $this->request, true);
- if (!$phone) return JsonService::fail('请输入手机号码');
- if (!$code) return JsonService::fail('请输入验证码');
- $code = md5('is_phone_code' . $code);
- if (!SmsCode::CheckCode($phone, $code)) return JsonService::fail('验证码验证失败');
- SmsCode::setCodeInvalid($phone, $code);
- $user = User::where(['phone' => $phone, 'is_h5user' => 0])->find();
- if ($type && $user) {
- if ($user['uid'] == $this->uid) {
- return JsonService::fail('不能绑定相同手机号');
- } else if ($user['uid'] != $this->uid) {
- return JsonService::fail('当前手机号码已绑定微信用户');
- }
- } else if ($type == 0 && $user) {
- if ($user) return JsonService::fail('当前手机号码已绑定微信用户');
- }
- //查找H5手机号码账户
- $phoneUser = PhoneUser::where(['phone' => $phone])->find();
- //H5页面有注册过
- if ($phoneUser && $phoneUser['uid'] != $this->uid) {
- //检测当前用户是否是H5用户
- if (User::where('uid', $phoneUser['uid'])->value('is_h5user')) {
- $res = User::setUserRelationInfos($phone, $phoneUser['uid'], $this->uid);
- if ($res === false) return JsonService::fail(User::getErrorInfo());
- }
- } else if ($phoneUser && $phoneUser['uid'] == $this->uid) {
- return JsonService::fail('不能绑定相同手机号');
- }
- if (!isset($res)) User::update(['phone' => $phone], ['uid' => $this->uid]);
- return JsonService::successful('绑定成功');
- } else {
- $this->assign('user_phone', $this->userInfo['phone']);
- return $this->fetch();
- }
- }
- /**
- * 个人中心
- * @return mixed
- * @throws \think\Exception
- */
- public function index()
- {
- $store_brokerage_statu = SystemConfigService::get('store_brokerage_statu');
- if ($store_brokerage_statu == 1) {
- if (isset($this->userInfo['is_promoter'])) $is_statu = $this->userInfo['is_promoter'] > 0 ? 1 : 0;
- else $is_statu = 0;
- } else if ($store_brokerage_statu == 2) {
- $is_statu = 1;
- }
- if (isset($this->userInfo['overdue_time'])) $overdue_time = date('Y-m-d', $this->userInfo['overdue_time']);
- else $overdue_time = 0;
- $this->assign([
- 'store_switch' => SystemConfigService::get('store_switch'),
- 'collectionNumber' => SpecialRelation::where('uid', $this->uid)->count(),
- 'recordNumber' => SpecialRecord::where('uid', $this->uid)->count(),
- 'overdue_time' => $overdue_time,
- 'is_statu' => $is_statu,
- ]);
- return $this->fetch();
- }
- /**虚拟币明细
- * @return mixed
- */
- public function gold_coin()
- {
- $gold_name = SystemConfigService::get('gold_name');//虚拟币名称
- $this->assign(compact('gold_name'));
- return $this->fetch('coin_detail');
- }
- /**签到
- * @return mixed
- */
- public function sign_in()
- {
- $urls = SystemConfigService::get('site_url') . '/';
- $gold_name = SystemConfigService::get('gold_name');//虚拟币名称
- $gold_coin = SystemConfigService::get('single_gold_coin');//签到获得虚拟币
- $signed = UserSign::checkUserSigned($this->uid);//今天是否签到
- $sign_image = $urls . "uploads/" . "poster_sign_" . $this->uid . ".png";
- $signCount = UserSign::userSignedCount($this->uid);//累记签到天数
- $this->assign(compact('signed', 'signCount', 'gold_name', 'gold_coin', 'sign_image'));
- return $this->fetch();
- }
- /**签到明细
- * @return mixed
- */
- public function sign_in_list()
- {
- return $this->fetch();
- }
- /**地址列表
- * @return mixed
- */
- public function address()
- {
- $address = UserAddress::getUserValidAddressList($this->uid, 'id,real_name,phone,province,city,district,detail,is_default');
- $this->assign([
- 'address' => json_encode($address)
- ]);
- return $this->fetch();
- }
- /**修改或添加地址
- * @param string $addressId
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function edit_address($addressId = '', $cartId = 0)
- {
- if ($addressId && is_numeric($addressId) && UserAddress::be(['is_del' => 0, 'id' => $addressId, 'uid' => $this->uid])) {
- $addressInfo = UserAddress::find($addressId)->toArray();
- } else {
- $addressInfo = [];
- }
- $addressInfo = json_encode($addressInfo);
- $this->assign(compact('addressInfo', 'cartId'));
- return $this->fetch();
- }
- /**订单详情
- * @param string $uni
- * @return mixed|void
- */
- public function order($uni = '')
- {
- if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->uid, $uni)) return $this->failed('查询订单不存在!');
- $this->assign([
- 'gold_name' => SystemConfigService::get('gold_name'),
- 'order' => StoreOrder::tidyOrder($order, true)
- ]);
- return $this->fetch();
- }
- public function orderPinkOld($uni = '')
- {
- if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->uid, $uni)) return $this->failed('查询订单不存在!');
- $this->assign([
- 'order' => StoreOrder::tidyOrder($order, true)
- ]);
- return $this->fetch('order');
- }
- /**获取订单
- * @param int $type
- * @param int $page
- * @param int $limit
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function get_order_list($type = -1, $page = 1, $limit = 10)
- {
- return JsonService::successful(StoreOrder::getSpecialOrderList((int)$type, (int)$page, (int)$limit, $this->uid));
- }
- /**我的拼课订单
- * @return mixed
- */
- public function order_list()
- {
- return $this->fetch();
- }
- /**申请退款
- * @param string $order_id
- * @return mixed
- */
- public function refund_apply($order_id = '')
- {
- if (!$order_id || !$order = StoreOrder::getUserOrderDetail($this->uid, $order_id)) return $this->failed('查询订单不存在!');
- $this->assign([
- 'order' => StoreOrder::tidyOrder($order, true, true),
- 'order_id' => $order_id
- ]);
- return $this->fetch();
- }
- /**评论页面
- * @param string $unique
- * @return mixed|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function order_reply($unique = '')
- {
- if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return $this->failed('评价产品不存在!');
- $this->assign(['cartInfo' => $cartInfo]);
- return $this->fetch();
- }
- /**物流查询
- * @param string $uni
- * @return mixed|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function express($uni = '')
- {
- if (!$uni || !($order = StoreOrder::getUserOrderDetail($this->uid, $uni))) return $this->failed('查询订单不存在!');
- if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!');
- $this->assign(['order' => StoreOrder::tidyOrder($order, true, true)]);
- return $this->fetch();
- }
- public function commission()
- {
- $uid = (int)Request::instance()->get('uid', 0);
- if (!$uid) return $this->failed('用户不存在!');
- $this->assign(['uid' => $uid]);
- return $this->fetch();
- }
- /**
- * 关于我们
- * @return mixed
- */
- public function about_us()
- {
- $this->assign([
- 'content' => get_config_content('about_us'),
- 'title' => '关于我们'
- ]);
- return $this->fetch('index/agree');
- }
- public function getUserGoldBill()
- {
- $user_info = $this->userInfo;
- list($page, $limit) = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ], $this->request, true);
- $where['uid'] = $user_info['uid'];
- $where['category'] = "gold_num";
- return JsonService::successful(UserBill::getUserGoldBill($where, $page, $limit));
- }
- /**
- * 余额明细
- */
- public function bill_detail()
- {
- return $this->fetch();
- }
- /**
- * 我的关注
- */
- public function follow_lecturer()
- {
- return $this->fetch();
- }
- /**
- * 课程浏览历史
- */
-
- public function special_log($page = 1, $limit = 20, $op = '') {
- if ($op == 'list') {
- $model = SpecialLog::alias('sl')->where('sl.mid', $this->uid)->page((int)$page, (int)$limit);
- $model = $model->join('Special s', 's.id = sl.sid');
- $model = $model->join('specialSubject ss', 's.subject_id = ss.id');
- $orderList = $model->order('sl.add_time DESC')->field('s.*, sl.add_time as log_time, ss.name as subject_name')->select();
- $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
- foreach ($orderList as &$item) {
- if (!isset($item['money'])) $item['money'] = 0;
- $item['money'] = (float)$item['money'];
- $item['image'] = get_oss_process($item['image'], 0);
- $item['count'] = 0;
- $specialSourceId = SpecialSource::getSpecialSource($item['id']);
- if ($specialSourceId) $item['count'] = count($specialSourceId);
- else $item['count'] = 0;
- }
- return JsonService::successful($orderList);
- }
- return $this->fetch();
- }
- /**
- * 我的学分
- */
- public function credit(){
-
- return $this->fetch();
- }
- /**
- * 学籍档案-学习记录
- */
- public function history($page = 1, $limit = 10000, $op = ''){
- if ($op == 'xuefenlist'){
- $model = SpecialBuy::alias('sb')->where('sb.uid', $this->uid)->page((int)$page, (int)$limit);
- $model = $model->join('Special s', 's.id = sb.special_id');
- $model = $model->join('specialSubject ss', 's.subject_id = ss.id');
- $orderList = $model->order('sb.add_time DESC')->field('s.*, sb.add_time as log_time, ss.name as subject_name')->select();
- $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
- $orderList1 = [];
- foreach ($orderList as &$item) {
- $flag = 1;
- if (!isset($item['money'])) $item['money'] = 0;
- $item['money'] = (float)$item['money'];
- $item['image'] = get_oss_process($item['image'], 0);
- $item['count'] = 0;
- $specialSourceId = SpecialSource::alias('ss')
- ->where('ss.special_id', $item['id'])
- ->field('ss.*, sw.viewing_time, sw.percentage')
- ->join('specialWatch sw', 'ss.special_id = sw.special_id and sw.uid = ' . $this->uid, 'left')
- ->select();
- if ($specialSourceId) $item['count'] = count($specialSourceId);
- foreach ($specialSourceId as $v) {
- if ($v['percentage'] < 100) {
- $flag = 0;
- break;
- }
- }
- if ($flag == 1){
- //关联试题
- //判断是否有考试
- $join1 = [
- ['ExaminationRecord er', 'er.test_id = r.relation_id and er.uid = ' . $this->uid, 'left'],
- ];
- $examlist = Relation::alias('r')
- ->where('r.relationship_id', $item['id'])
- ->where('r.relationship', 2)
- ->field('r.relation_id as test_id, er.score')->join($join1)->select();
- if ($examlist) {
- foreach ($examlist as $v) {
- if ($v['score'] < 60) {
- $flag = 0;
- break;
- }
- }
- }
- }
- if ($flag == 1) {
- $orderList1[] = $item;
- }
- }
- return JsonService::successful($orderList1);
- }
- //时长获取
- if ($op == 'shichanglist'){
- $model = SpecialBuy::alias('sb')->where('sb.uid', $this->uid)->page((int)$page, (int)$limit);
- $model = $model->join('Special s', 's.id = sb.special_id');
- $model = $model->join('specialSubject ss', 's.subject_id = ss.id');
- $orderList = $model->order('sb.add_time DESC')->field('s.*, sb.add_time as log_time, ss.name as subject_name')->select();
- $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
- foreach ($orderList as &$item) {
- if (!isset($item['money'])) $item['money'] = 0;
- $item['money'] = (float)$item['money'];
- $item['image'] = get_oss_process($item['image'], 0);
- $item['count'] = 0;
- $item['shichang'] = 0;
- $specialSourceId = SpecialSource::alias('ss')
- ->where('ss.special_id', $item['id'])
- ->field('ss.*, sw.viewing_time, sw.percentage')
- ->join('specialWatch sw', 'ss.special_id = sw.special_id and sw.uid = ' . $this->uid, 'left')
- ->select();
- if ($specialSourceId) $item['count'] = count($specialSourceId);
- foreach ($specialSourceId as $v) {
- $item['shichang'] += $v['viewing_time'];
- }
- }
- return JsonService::successful($orderList);
- }
- return $this->fetch();
- }
- }
|