ApplyRecordController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace plugin\admin\app\controller;
  3. use app\api\repositories\MoneyLogRepositories;
  4. use app\business\StreamBusiness;
  5. use Illuminate\Support\Arr;
  6. use plugin\admin\app\model\ApplyRecord;
  7. use plugin\admin\app\repositories\WithdrawRepositories;
  8. use Respect\Validation\Validator;
  9. use support\Db;
  10. use support\Log;
  11. use support\Request;
  12. use support\Response;
  13. use plugin\admin\app\model\Withdraw;
  14. use plugin\admin\app\controller\Crud;
  15. use support\exception\BusinessException;
  16. /**
  17. * 提现列表
  18. */
  19. class ApplyRecordController extends Crud
  20. {
  21. /**
  22. * @var ApplyRecord
  23. */
  24. protected $model = null;
  25. /**
  26. * 构造函数
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new ApplyRecord();
  32. }
  33. /**
  34. * 浏览
  35. * @return Response
  36. */
  37. public function index(): Response
  38. {
  39. return view('applyrecord/index');
  40. }
  41. /**
  42. * 更新
  43. * @param Request $request
  44. * @return Response
  45. * @throws BusinessException
  46. */
  47. public function update(Request $request): Response
  48. {
  49. if ($request->method() === 'POST') {
  50. return parent::update($request);
  51. }
  52. return view('applyrecord/update');
  53. }
  54. /**查询收银余额
  55. * @param Request $request
  56. * @return Response
  57. */
  58. public function select(Request $request): Response
  59. {
  60. $param = $request->all();
  61. $data = ApplyRecord::query()->where(function ($query) use ($param) {
  62. if (Arr::get($param, 'created_at.0') && Arr::get($param, 'created_at.1')) {
  63. $query->whereBetween('created_at', [$param['created_at'][0], $param['created_at'][1]]);
  64. } elseif (Arr::get($param, 'created_at.0')) {
  65. $query->where('created_at', '>=', $param['created_at'][0]);
  66. } elseif (Arr::get($param, 'created_at.1')) {
  67. $query->where('created_at', '<=', $param['created_at'][1]);
  68. }
  69. if (Arr::get($param, 'status')) {
  70. $query->where('status', $param['status']);
  71. }
  72. if (Arr::get($param, 'type')) {
  73. $query->where('type', $param['type']);
  74. }
  75. if (Arr::get($param, 'id')) {
  76. $query->where('id', $param['id']);
  77. }
  78. })->whereExists(function ($query) use ($param) {
  79. $query->from('wa_users')->whereRaw('wa_users.id=wa_apply_record.uid');
  80. if (Arr::get($param, 'user_name')) {
  81. $query->where('name', 'like', '%' . $param['user_name'] . '%');
  82. }
  83. if (Arr::get($param, 'mobile')) {
  84. $query->where('mobile', 'like', '%' . $param['mobile'] . '%');
  85. }
  86. })
  87. ->with('userData:id,name,mobile');
  88. if (Arr::get($param, 'field')) {
  89. $order = 'asc';
  90. if (Arr::get($param, 'order')) {
  91. $order = 'desc';
  92. }
  93. $data = $data->orderBy($param['field'], $order);
  94. } else {
  95. $data = $data->orderByDesc('id');
  96. }
  97. $data = $data->paginate(Arr::get($param, 'limit', 10))->toArray();
  98. $arr = [];
  99. foreach ($data['data'] as $k => $v) {
  100. $arr[] = [
  101. 'id' => $v['id'],
  102. 'user_name' => $v['user_data']['name'],
  103. 'user_mobile' => $v['user_data']['mobile'],
  104. 'money' => $v['money'],
  105. 'type' => $v['type'],
  106. 'name' => $v['name'],
  107. 'mobile' => $v['mobile'],
  108. 'card_number' => $v['card_number'],
  109. 'status' => $v['status'],
  110. 'created_at' => $v['created_at'],
  111. 'certificate_img' => $v['certificate_img'],
  112. 'scale' => $v['scale'],
  113. 'address' => $v['province'] . $v['address']
  114. ];
  115. }
  116. return json(['code' => 0, 'data' => $arr, 'msg' => 'ok', 'count' => $data['total']]);
  117. }
  118. /** 批量通过
  119. * @param Request $request
  120. * @return Response
  121. */
  122. public function pass(Request $request): Response
  123. {
  124. try {
  125. $param = $request->all();
  126. Validator::input($param, [
  127. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  128. ]);
  129. $applyRecordModel = ApplyRecord::query();
  130. foreach ($param['id'] as $k => $v) {
  131. Db::beginTransaction();
  132. try {
  133. $system = Db::table('wa_system')->first();
  134. $has = (clone $applyRecordModel)->where('id', $v)->lock(true)->first();
  135. if (empty($has)) {
  136. throw new \Exception('申请数据不存在!');
  137. }
  138. if ($has->status != 1) {
  139. throw new \Exception('申请数据已经处理!');
  140. }
  141. if ($has && $has->status == 1) {
  142. StreamBusiness::addStream($has->uid, $has->money, streamType15, moldType1, moldTypefild1, $v);
  143. $has->status = 2;
  144. $has->updated_at = date('Y-m-d H:i:s');
  145. $has->save();
  146. } else {
  147. throw new \Exception('已处理请不要重复提交!');
  148. }
  149. Db::commit();
  150. } catch (\Throwable $exception) {
  151. Db::rollBack();
  152. throw new \Exception($exception->getMessage());
  153. }
  154. }
  155. } catch (\Throwable $exception) {
  156. return $this->fail($exception->getMessage());
  157. }
  158. return $this->success();
  159. }
  160. /** 批量发布
  161. * @param Request $request
  162. * @return Response
  163. */
  164. public function release(Request $request): Response
  165. {
  166. try {
  167. $param = $request->all();
  168. Validator::input($param, [
  169. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  170. ]);
  171. $signRecordModel = ApplyRecord::query();
  172. foreach ($param['id'] as $k => $v) {
  173. Db::beginTransaction();
  174. try {
  175. $has = (clone $signRecordModel)->where('id', $v)->lock(true)->first();
  176. if (empty($has)) {
  177. throw new \Exception('申请数据不存在!');
  178. }
  179. if ($has->status == 4) {
  180. throw new \Exception('申请数据已经发货!');
  181. }
  182. if ($has && $has->status == 2) {
  183. $has->status = 4;
  184. $has->updated_at = date('Y-m-d H:i:s');
  185. $has->save();
  186. } else {
  187. throw new \Exception('已处理请不要重复提交!');
  188. }
  189. Db::commit();
  190. } catch (\Throwable $exception) {
  191. Db::rollBack();
  192. throw new \Exception($exception->getMessage());
  193. }
  194. }
  195. } catch (\Throwable $exception) {
  196. return $this->fail($exception->getMessage());
  197. }
  198. return $this->success();
  199. }
  200. /** 批量驳回
  201. * @param Request $request
  202. * @return Response
  203. */
  204. public function reject(Request $request): Response
  205. {
  206. try {
  207. $param = $request->all();
  208. Validator::input($param, [
  209. 'id' => Validator::notEmpty()->ArrayType()->setName('标识'),
  210. ]);
  211. $applyRecordModel = ApplyRecord::query();
  212. foreach ($param['id'] as $k => $v) {
  213. Db::beginTransaction();
  214. try {
  215. $has = (clone $applyRecordModel)->where('id', $v)->lock(true)->first();
  216. if (empty($has)) {
  217. throw new \Exception('暂无数据');
  218. }
  219. if ($has->status != 1) {
  220. throw new \Exception('已被审核!');
  221. }
  222. $has->status = 3;
  223. $has->save();
  224. } catch (\Throwable $exception) {
  225. Db::rollBack();
  226. throw new \Exception($exception->getMessage());
  227. }
  228. Db::commit();
  229. }
  230. } catch (\Throwable $exception) {
  231. return $this->fail($exception->getMessage());
  232. }
  233. return $this->success();
  234. }
  235. }