Commission.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. namespace app\controller\admin;
  3. use app\service\api\UserServiceFacade;
  4. use app\service\api\PayServiceFacade;
  5. use app\validate\admin\notice\Add;
  6. use laytp\controller\Backend;
  7. use laytp\library\CommonFun;
  8. use laytp\library\UploadDomain;
  9. use app\service\ConfServiceFacade;
  10. use think\facade\Db;
  11. use think\facade\Config;
  12. /**
  13. * 会员管理
  14. */
  15. class Commission extends Backend
  16. {
  17. protected $model;//当前模型对象
  18. protected $noNeedLogin = [];
  19. protected $noNeedAuth = [];
  20. protected function _initialize()
  21. {
  22. $this->modelUser = new \app\model\commission\User();
  23. }
  24. //查看
  25. public function index()
  26. {
  27. $where = $this->buildSearchParams();
  28. // $order = ['uid'=>'DESC'];
  29. $order = ['create_time' => 'desc'];
  30. $data = $this->modelUser->order($order)->where($where)->with(['userinfo','pid_userinfo.pidUserinfo'])->withCount(['commission1','commission2','commission3'])->withSum('income','money');
  31. $allData = $this->request->param('all_data');
  32. if ($allData) {
  33. $data = $data->select();
  34. } else {
  35. $limit = $this->request->param('limit', 10);
  36. $data = $data->paginate($limit)->toArray();
  37. }
  38. return $this->success('数据获取成功', $data);
  39. }
  40. //查看和搜索列表
  41. public function settle(){
  42. global $_W;
  43. $modelSettle = new \app\model\commission\Settle();
  44. $where = $this->buildSearchParams();
  45. $where[] = ['uniacid','=',$_W['uniacid']];
  46. $where[] = ['paid','=',1];
  47. $order = $this->buildOrder();
  48. $data = $modelSettle->where($where)->order($order)->with(['userInfo']);
  49. $paging = $this->request->param('paging', false);
  50. if ($paging) {
  51. $limit = $this->request->param('limit', Config::get('paginate.limit'));
  52. $data = $data->paginate($limit)->toArray();
  53. $data['data'] = $this->getSelectedData($data['data']);
  54. } else {
  55. $data = $data->select()->toArray();
  56. }
  57. return $this->success('数据获取成功', $data);
  58. }
  59. //查看
  60. public function income()
  61. {
  62. $modelIncome = new \app\model\commission\Income();
  63. $where = $this->buildSearchParams();
  64. $order = ['id'=>'DESC'];
  65. $data = $modelIncome->where($where)->order($order)->with(['userinfo','buyUserinfo']);
  66. $allData = $this->request->param('all_data');
  67. if ($allData) {
  68. $data = $data->select();
  69. } else {
  70. $limit = $this->request->param('limit', 10);
  71. $data = $data->paginate($limit)->toArray();
  72. }
  73. return $this->success('数据获取成功', $data);
  74. }
  75. //查看
  76. public function cashout()
  77. {
  78. $modelCashout = new \app\model\commission\Cashout();
  79. $where = $this->buildSearchParams();
  80. // print_r($where);
  81. $order = ['id'=>'DESC'];
  82. $data = $modelCashout->where($where)->order($order)->with(['userinfo','commission_userinfo.img_file']);
  83. $allData = $this->request->param('all_data');
  84. if ($allData) {
  85. $data = $data->select();
  86. } else {
  87. $limit = $this->request->param('limit', 10);
  88. $data = $data->paginate($limit)->toArray();
  89. }
  90. return $this->success('数据获取成功', $data);
  91. }
  92. //提现详情
  93. public function cashoutInfo()
  94. {
  95. $id = $this->request->param('id');
  96. $info = \app\model\commission\Cashout::with(['commission_userinfo.img_file'])->find($id)->toArray();
  97. return $this->success('获取成功', $info);
  98. }
  99. // 提现设置状态
  100. public function cashoutSetStatus()
  101. {
  102. $model = new \app\model\commission\Cashout();
  103. // $app = PayServiceFacade::option();
  104. $id = $this->request->post('id');
  105. $fieldVal = $this->request->post('status');
  106. $failMsg = $this->request->post('fail_msg','');
  107. $isRecycle = $this->request->post('is_recycle');
  108. $mode = $this->request->post('mode');
  109. $update['status'] = $fieldVal;
  110. $update['fail_msg'] = $failMsg;
  111. $info = $model::find($id);
  112. // print_r($info);
  113. $userInfo = \app\model\User::find($info['uid']);
  114. if(!$userInfo){
  115. return $this->error('未查询到此用户注册信息');
  116. }
  117. if($fieldVal == 1){
  118. if(!$mode){
  119. return $this->error('请选择付款方式');
  120. }
  121. if($mode == 2){
  122. $pay = ConfServiceFacade::groupGet('system.pay', true);
  123. if(!$pay['cert_filename'] || !$pay['key_filename']){
  124. return $this->error('未上传证书');
  125. }
  126. $openid = $userInfo['openid_wechat']?$userInfo['openid_wechat']:$userInfo['openid_miniapp'];
  127. // if(!$openid){
  128. // return $this->error('此用户不是从微信登录,无法使用在线打款');
  129. // }
  130. // var_dump($openid);
  131. $nMoney = number_format($info['extract_price'])*100;
  132. $result = PayServiceFacade::transfer_batches($openid, $nMoney);
  133. // print_r($result);
  134. // $app = PayServiceFacade::option($info['extract_type']);
  135. // $result = $app->transfer->toBalance([
  136. // 'partner_trade_no' => $id, // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  137. // 'openid' => $userInfo['openid_wechat']?$userInfo['openid_wechat']:$userInfo['openid_miniapp'],
  138. // 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
  139. // 're_user_name' => $info['uid'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  140. // 'amount' => number_format($info['extract_price'])*100, // 企业付款金额,单位为分
  141. // 'desc' => '费', // 企业付款操作说明信息。必填
  142. // ]);
  143. // // print_r($result);
  144. // if($result['return_code'] =='SUCCESS'){
  145. // if($result['result_code'] =='FAIL'){
  146. // return $this->error('操作失败:'.$result['return_msg'].$result['err_code_des']);
  147. // }
  148. // }else{
  149. // return $this->error('操作失败');
  150. // }
  151. }
  152. }
  153. try {
  154. $updateRes = $model->where('id', '=', $id)->update($update);
  155. if ($updateRes) {
  156. return $this->success('操作成功');
  157. } else if ($updateRes === 0) {
  158. return $this->success('未作修改');
  159. } else {
  160. return $this->error('操作失败');
  161. }
  162. } catch (\Exception $e) {
  163. return $this->error('数据库异常,操作失败');
  164. }
  165. }
  166. //添加
  167. public function add()
  168. {
  169. global $_W;
  170. Db::startTrans();
  171. try {
  172. $post = CommonFun::filterPostData($this->request->post());
  173. $post['uniacid'] = $_W['uniacid'];
  174. $validate = new Add();
  175. if (!$validate->check($post)) throw new \Exception($validate->getError());
  176. $result = $this->modelUser->save($post);
  177. if(!$result) throw new \Exception("添加失败");
  178. Db::commit();
  179. return $this->success('添加成功');
  180. } catch (\Exception $e) {
  181. Db::rollback();
  182. return $this->exceptionError($e);
  183. }
  184. }
  185. //查看详情
  186. public function info()
  187. {
  188. $id = $this->request->param('id');
  189. // print_r($id );
  190. $info = $this->modelUser->where('uid','=',$id)->findOrEmpty()->toArray();
  191. return $this->success('获取成功', $info);
  192. }
  193. //编辑
  194. public function edit()
  195. {
  196. Db::startTrans();
  197. try {
  198. $post = CommonFun::filterPostData($this->request->post());
  199. $navmenu = $this->modelUser->findOrEmpty($post['id']);
  200. if (!$navmenu) throw new \Exception("id参数错误");
  201. $validate = new Add();
  202. if (!$validate->check($post)) throw new \Exception($validate->getError());
  203. $updateNavmenu = $navmenu->update($post);
  204. if (!$updateNavmenu) throw new \Exception("菜单基本信息保存失败");
  205. Db::commit();
  206. return $this->success('操作成功');
  207. } catch (\Exception $e) {
  208. Db::rollback();
  209. return $this->exceptionError($e);
  210. }
  211. }
  212. //删除
  213. public function del()
  214. {
  215. $ids = array_filter($this->request->param('ids'));
  216. if (!$ids) {
  217. return $this->error('参数ids不能为空');
  218. }
  219. // if (in_array(1, $ids)) {
  220. // return $this->error('不允许删除初始化用户');
  221. // }
  222. try{
  223. if ($this->modelUser->destroy($ids)) {
  224. return $this->success('数据删除成功');
  225. } else {
  226. return $this->error('数据删除失败');
  227. }
  228. }catch (\Exception $e){
  229. return $this->exceptionError($e);
  230. }
  231. }
  232. //设置状态
  233. public function setStatus()
  234. {
  235. $id = $this->request->post('id');
  236. $fieldVal = $this->request->post('field_val');
  237. $isRecycle = $this->request->post('is_recycle');
  238. $update['status'] = $fieldVal;
  239. // try {
  240. if($isRecycle) {
  241. $updateRes = $this->modelUser->onlyTrashed()->where('uid', '=', $id)->update($update);
  242. } else {
  243. $updateRes = $this->modelUser->where('uid', '=', $id)->update($update);
  244. }
  245. if ($updateRes) {
  246. return $this->success('操作成功');
  247. } else if ($updateRes === 0) {
  248. return $this->success('未作修改');
  249. } else {
  250. return $this->error('操作失败');
  251. }
  252. // } catch (\Exception $e) {
  253. // return $this->error('数据库异常,操作失败');
  254. // }
  255. }
  256. }