123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <?php
- namespace app\controller\admin;
- use app\service\api\UserServiceFacade;
- use app\service\api\PayServiceFacade;
- use app\validate\admin\notice\Add;
- use laytp\controller\Backend;
- use laytp\library\CommonFun;
- use laytp\library\UploadDomain;
- use app\service\ConfServiceFacade;
- use think\facade\Db;
- use think\facade\Config;
- /**
- * 会员管理
- */
- class Commission extends Backend
- {
- protected $model;//当前模型对象
- protected $noNeedLogin = [];
- protected $noNeedAuth = [];
- protected function _initialize()
- {
- $this->modelUser = new \app\model\commission\User();
- }
- //查看
- public function index()
- {
- $where = $this->buildSearchParams();
- // $order = ['uid'=>'DESC'];
- $order = ['create_time' => 'desc'];
- $data = $this->modelUser->order($order)->where($where)->with(['userinfo','pid_userinfo.pidUserinfo'])->withCount(['commission1','commission2','commission3'])->withSum('income','money');
- $allData = $this->request->param('all_data');
- if ($allData) {
- $data = $data->select();
- } else {
- $limit = $this->request->param('limit', 10);
- $data = $data->paginate($limit)->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- //查看和搜索列表
- public function settle(){
- global $_W;
- $modelSettle = new \app\model\commission\Settle();
- $where = $this->buildSearchParams();
- $where[] = ['uniacid','=',$_W['uniacid']];
- $where[] = ['paid','=',1];
- $order = $this->buildOrder();
- $data = $modelSettle->where($where)->order($order)->with(['userInfo']);
- $paging = $this->request->param('paging', false);
- if ($paging) {
- $limit = $this->request->param('limit', Config::get('paginate.limit'));
- $data = $data->paginate($limit)->toArray();
- $data['data'] = $this->getSelectedData($data['data']);
- } else {
- $data = $data->select()->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- //查看
- public function income()
- {
- $modelIncome = new \app\model\commission\Income();
- $where = $this->buildSearchParams();
- $order = ['id'=>'DESC'];
- $data = $modelIncome->where($where)->order($order)->with(['userinfo','buyUserinfo']);
- $allData = $this->request->param('all_data');
- if ($allData) {
- $data = $data->select();
- } else {
- $limit = $this->request->param('limit', 10);
- $data = $data->paginate($limit)->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- //查看
- public function cashout()
- {
- $modelCashout = new \app\model\commission\Cashout();
- $where = $this->buildSearchParams();
- // print_r($where);
- $order = ['id'=>'DESC'];
- $data = $modelCashout->where($where)->order($order)->with(['userinfo','commission_userinfo.img_file']);
- $allData = $this->request->param('all_data');
- if ($allData) {
- $data = $data->select();
- } else {
- $limit = $this->request->param('limit', 10);
- $data = $data->paginate($limit)->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- //提现详情
- public function cashoutInfo()
- {
- $id = $this->request->param('id');
- $info = \app\model\commission\Cashout::with(['commission_userinfo.img_file'])->find($id)->toArray();
- return $this->success('获取成功', $info);
- }
- // 提现设置状态
- public function cashoutSetStatus()
- {
- $model = new \app\model\commission\Cashout();
- // $app = PayServiceFacade::option();
- $id = $this->request->post('id');
- $fieldVal = $this->request->post('status');
- $failMsg = $this->request->post('fail_msg','');
- $isRecycle = $this->request->post('is_recycle');
- $mode = $this->request->post('mode');
- $update['status'] = $fieldVal;
- $update['fail_msg'] = $failMsg;
- $info = $model::find($id);
- // print_r($info);
- $userInfo = \app\model\User::find($info['uid']);
- if(!$userInfo){
- return $this->error('未查询到此用户注册信息');
- }
- if($fieldVal == 1){
- if(!$mode){
- return $this->error('请选择付款方式');
- }
- if($mode == 2){
- $pay = ConfServiceFacade::groupGet('system.pay', true);
- if(!$pay['cert_filename'] || !$pay['key_filename']){
- return $this->error('未上传证书');
- }
- $openid = $userInfo['openid_wechat']?$userInfo['openid_wechat']:$userInfo['openid_miniapp'];
- // if(!$openid){
- // return $this->error('此用户不是从微信登录,无法使用在线打款');
- // }
- // var_dump($openid);
- $nMoney = number_format($info['extract_price'])*100;
- $result = PayServiceFacade::transfer_batches($openid, $nMoney);
- // print_r($result);
- // $app = PayServiceFacade::option($info['extract_type']);
- // $result = $app->transfer->toBalance([
- // 'partner_trade_no' => $id, // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
- // 'openid' => $userInfo['openid_wechat']?$userInfo['openid_wechat']:$userInfo['openid_miniapp'],
- // 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
- // 're_user_name' => $info['uid'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
- // 'amount' => number_format($info['extract_price'])*100, // 企业付款金额,单位为分
- // 'desc' => '费', // 企业付款操作说明信息。必填
- // ]);
- // // print_r($result);
- // if($result['return_code'] =='SUCCESS'){
- // if($result['result_code'] =='FAIL'){
- // return $this->error('操作失败:'.$result['return_msg'].$result['err_code_des']);
- // }
- // }else{
- // return $this->error('操作失败');
- // }
- }
- }
- try {
- $updateRes = $model->where('id', '=', $id)->update($update);
- if ($updateRes) {
- return $this->success('操作成功');
- } else if ($updateRes === 0) {
- return $this->success('未作修改');
- } else {
- return $this->error('操作失败');
- }
- } catch (\Exception $e) {
- return $this->error('数据库异常,操作失败');
- }
- }
- //添加
- public function add()
- {
- global $_W;
- Db::startTrans();
- try {
- $post = CommonFun::filterPostData($this->request->post());
- $post['uniacid'] = $_W['uniacid'];
- $validate = new Add();
- if (!$validate->check($post)) throw new \Exception($validate->getError());
- $result = $this->modelUser->save($post);
- if(!$result) throw new \Exception("添加失败");
- Db::commit();
- return $this->success('添加成功');
- } catch (\Exception $e) {
- Db::rollback();
- return $this->exceptionError($e);
- }
- }
- //查看详情
- public function info()
- {
- $id = $this->request->param('id');
- // print_r($id );
- $info = $this->modelUser->where('uid','=',$id)->findOrEmpty()->toArray();
- return $this->success('获取成功', $info);
- }
- //编辑
- public function edit()
- {
- Db::startTrans();
- try {
- $post = CommonFun::filterPostData($this->request->post());
- $navmenu = $this->modelUser->findOrEmpty($post['id']);
- if (!$navmenu) throw new \Exception("id参数错误");
- $validate = new Add();
- if (!$validate->check($post)) throw new \Exception($validate->getError());
- $updateNavmenu = $navmenu->update($post);
- if (!$updateNavmenu) throw new \Exception("菜单基本信息保存失败");
- Db::commit();
- return $this->success('操作成功');
- } catch (\Exception $e) {
- Db::rollback();
- return $this->exceptionError($e);
- }
- }
- //删除
- public function del()
- {
- $ids = array_filter($this->request->param('ids'));
- if (!$ids) {
- return $this->error('参数ids不能为空');
- }
- // if (in_array(1, $ids)) {
- // return $this->error('不允许删除初始化用户');
- // }
- try{
- if ($this->modelUser->destroy($ids)) {
- return $this->success('数据删除成功');
- } else {
- return $this->error('数据删除失败');
- }
- }catch (\Exception $e){
- return $this->exceptionError($e);
- }
- }
- //设置状态
- public function setStatus()
- {
- $id = $this->request->post('id');
- $fieldVal = $this->request->post('field_val');
- $isRecycle = $this->request->post('is_recycle');
- $update['status'] = $fieldVal;
- // try {
- if($isRecycle) {
- $updateRes = $this->modelUser->onlyTrashed()->where('uid', '=', $id)->update($update);
- } else {
- $updateRes = $this->modelUser->where('uid', '=', $id)->update($update);
- }
- if ($updateRes) {
- return $this->success('操作成功');
- } else if ($updateRes === 0) {
- return $this->success('未作修改');
- } else {
- return $this->error('操作失败');
- }
- // } catch (\Exception $e) {
- // return $this->error('数据库异常,操作失败');
- // }
- }
- }
|