MemberExtract.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\admin\controller;
  3. use app\api\controller\WxPay;
  4. use app\admin\model\ShopUser;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. use app\admin\model\Member;
  10. /**
  11. * 用户提现管理
  12. *
  13. * @icon fa fa-circle-o
  14. */
  15. class MemberExtract extends Backend
  16. {
  17. /**
  18. * MemberExtract模型对象
  19. * @var \app\admin\model\MemberExtract
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\MemberExtract;
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. */
  35. public function index($suser_id=null)
  36. {
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags']);
  39. if ($this->request->isAjax()) {
  40. //如果发送的来源是Selectpage,则转发到Selectpage
  41. if ($this->request->request('keyField')) {
  42. return $this->selectpage();
  43. }
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $whre1=[];
  46. if (!empty($suser_id)){
  47. $whre1['type']='1';
  48. $whre1['suser_id']=$suser_id;
  49. }
  50. $total = $this->model
  51. ->where($where)
  52. ->where('is_del','0')
  53. ->where('is_system_del','0')
  54. ->where($whre1)
  55. ->order($sort, $order)
  56. ->count();
  57. $list = $this->model
  58. ->where($where)
  59. ->where('is_del','0')
  60. ->where('is_system_del','0')
  61. ->where($whre1)
  62. ->with('member')
  63. ->order($sort, $order)
  64. ->limit($offset, $limit)
  65. ->select();
  66. $list = collection($list)->toArray();
  67. $result = array("total" => $total, "rows" => $list);
  68. return json($result);
  69. }
  70. return $this->view->fetch();
  71. }
  72. /**
  73. * 编辑
  74. */
  75. public function edit($ids = null)
  76. {
  77. $row = $this->model->get($ids);
  78. if (!$row) {
  79. $this->error(__('No Results were found'));
  80. }
  81. $adminIds = $this->getDataLimitAdminIds();
  82. if (is_array($adminIds)) {
  83. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  84. $this->error(__('You have no permission'));
  85. }
  86. }
  87. if ($this->request->isPost()) {
  88. $params = $this->request->post("row/a");
  89. if ($params) {
  90. $params = $this->preExcludeFields($params);
  91. $get_member=Member::where('mid',$row['mid'])->field('openid,mid')->find();
  92. if (empty($get_member['openid'])){
  93. $this->error(__('用户信息错误,不可以提现'));
  94. }
  95. $result = false;
  96. Db::startTrans();
  97. try {
  98. //是否采用模型验证
  99. if ($this->modelValidate) {
  100. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  101. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  102. $row->validateFailException(true)->validate($validate);
  103. }
  104. if ($params['status']=='1'){
  105. $wx = new WxPay();//实例化微信支付控制器
  106. $order = $wx->tixian($row['extract_id'],$row['real_name'],$row['extract_price']*100,$get_member['openid']);
  107. if(($order['return_code']=='SUCCESS') && ($order['result_code']=='SUCCESS')){
  108. $result = $row->allowField(true)->save($params);
  109. // $this->model->where(['id' => $ids])->update(['refund_status'=>'5','refund_reason'=>$refund_reason,'status'=>'-5']);
  110. $this->success("成功", null, ['id' => $ids]);
  111. }else if(($order['return_code']=='FAIL') || $order['result_code']=='FAIL' ){
  112. $reason = (empty($order['err_code_des'])?$order['return_msg']:$order['err_code_des']);
  113. $this->error($reason);
  114. }else{
  115. $this->error("处理失败");
  116. }
  117. }elseif ($params['status']=='2'){
  118. if ($row['type']=='1'){
  119. ShopUser::where('id',$row['suser_id'])->setInc('balance',$row['extract_price']);
  120. }else{
  121. Member::where('mid',$row['mid'])->setInc('brokerage_price',$row['extract_price']);
  122. }
  123. $result = $row->allowField(true)->save($params);
  124. }
  125. Db::commit();
  126. } catch (ValidateException $e) {
  127. Db::rollback();
  128. $this->error($e->getMessage());
  129. } catch (PDOException $e) {
  130. Db::rollback();
  131. $this->error($e->getMessage());
  132. } catch (Exception $e) {
  133. Db::rollback();
  134. $this->error($e->getMessage());
  135. }
  136. if ($result !== false) {
  137. $this->success();
  138. } else {
  139. $this->error(__('No rows were updated'));
  140. }
  141. }
  142. $this->error(__('Parameter %s can not be empty', ''));
  143. }
  144. $this->view->assign("row", $row);
  145. return $this->view->fetch();
  146. }
  147. /**
  148. * 删除
  149. */
  150. public function del($ids = "")
  151. {
  152. if ($ids) {
  153. $pk = $this->model->getPk();
  154. $adminIds = $this->getDataLimitAdminIds();
  155. if (is_array($adminIds)) {
  156. $this->model->where($this->dataLimitField, 'in', $adminIds);
  157. }
  158. $list = $this->model->where($pk, 'in', $ids)->select();
  159. $count = 0;
  160. Db::startTrans();
  161. try {
  162. foreach ($list as $k => $v) {
  163. $count += $v->save(['is_system_del'=>1]);
  164. }
  165. Db::commit();
  166. } catch (PDOException $e) {
  167. Db::rollback();
  168. $this->error($e->getMessage());
  169. } catch (Exception $e) {
  170. Db::rollback();
  171. $this->error($e->getMessage());
  172. }
  173. if ($count) {
  174. $this->success();
  175. } else {
  176. $this->error(__('No rows were deleted'));
  177. }
  178. }
  179. $this->error(__('Parameter %s can not be empty', 'ids'));
  180. }
  181. }