SignRecordController.php 8.9 KB

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