123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\admin\controller\finance;
- use app\admin\service\goods\GoodsSkuService;
- use app\admin\service\member\MemberService;
- use app\controller\Curd;
- use app\model\ClientConfig;
- use app\model\Member;
- use app\model\MemberAccount;
- use app\model\MemberAccountList;
- use app\model\Order;
- use app\model\OrderSheet;
- use support\Db;
- use support\exception\BusinessException;
- use support\Request;
- use support\Response;
- use Webman\Event\Event;
- class WithdrawalListController extends Curd
- {
- public function __construct()
- {
- $this->model = new MemberAccountList();
- }
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $order = $request->get('order', 'desc');
- $field = $field ?? 'member_account_list_addtimes';
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- protected function doSelect(array $where, string $field = null, string $order = 'desc')
- {
- $model = $this->model->with([
- 'member' => function ($query) {
- $query->select('member_id', 'member_mobile', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer');
- },
- 'memberInfo' => function ($query) {
- $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
- },
- 'memberCert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- }
- ]);
- foreach ($where as $column => $value) {
- if (is_array($value)) {
- if ($value[0] === 'like' || $value[0] === 'not like') {
- $model = $model->where($column, $value[0], "%$value[1]%");
- } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
- $model = $model->where($column, $value[0], $value[1]);
- } elseif ($value[0] == 'in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereIn($column, $valArr);
- } elseif ($value[0] == 'not in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereNotIn($column, $valArr);
- } elseif ($value[0] == 'null') {
- $model = $model->whereNull($column);
- } elseif ($value[0] == 'not null') {
- $model = $model->whereNotNull($column);
- } elseif ($value[0] !== '' || $value[1] !== '') {
- $model = $model->whereBetween($column, $value);
- }
- } else {
- $model = $model->where($column, $value);
- }
- }
- if ($field) {
- $model = $model->orderBy($field, $order);
- }
- return $model;
- }
- public function afterQuery($items)
- {
- foreach ($items as &$item) {
- $item['member_mobile'] = isset($item['member']) ? $item['member']['member_mobile'] : '';
- $item['member_info_nickname'] = isset($item['memberInfo']) && !empty($item['memberInfo']['member_info_nickname']) ? $item['memberInfo']['member_info_nickname'] : '';
- $item['member_cert_name'] = isset($item['memberCert']) && !empty($item['memberCert']['member_cert_name']) ? $item['memberCert']['member_cert_name'] : '';
- $item['member_name'] = MemberService::getMemberName($item['member_mobile'], $item['member_cert_name'], $item['member_info_nickname']);
- $item['member_info_headimg'] = isset($item['memberInfo']) && !empty($item['memberInfo']['member_info_headimg']) ? $item['memberInfo']['member_info_headimg'] : "";
- $item['member_is_owner'] = isset($item['member']) ? $item['member']['member_is_owner'] : '';
- $item['member_is_vip'] = isset($item['member']) ? $item['member']['member_is_vip'] : '';
- $item['member_is_partner'] = isset($item['member']) ? $item['member']['member_is_partner'] : '';
- $item['member_is_referrer'] = isset($item['member']) ? $item['member']['member_is_referrer'] : '';
- unset($item['member'], $item['memberInfo'], $item['memberCert']);
- }
- return $items;
- }
- /**
- * @Desc 记录详情
- * @Author Gorden
- * @Date 2024/9/28 17:15
- *
- * @param Request $request
- * @return Response
- */
- public function info(Request $request): Response
- {
- $id = $request->get('member_account_list_id');
- if (!$id) {
- return json_fail("参数异常");
- }
- $info = MemberAccountList::where('member_account_list_id', $id)->first();
- $infoMember = Member::with([
- 'role' => function ($query) {
- $query->select('member_role_id', 'member_role_name');
- }
- ])->where('member_id', $info->join_member_account_list_member_id)
- ->first();
- $info->member_role_name = !empty($infoMember->role) ? $infoMember->role->member_role_name : '';
- // 获取银行卡信息
- if (!empty($info->member_account_list_json)) {
- $accountListJson = json_decode($info->member_account_list_json, true);
- $info->banks = [
- [
- 'bank_name' => $accountListJson['bank_name'] ?? '',
- 'username' => $accountListJson['bank_acount'] ?? '',
- 'cardno' => $accountListJson['bank_cardno'] ?? ''
- ]
- ];
- }
- // $info->banks = ClientConfig::where('join_client_config_member_id',$info->join_member_account_list_member_id)->where('client_config_key','client-bank')->get()->toArray();
- return json_success('success', $info);
- }
- public function changeStatus(Request $request)
- {
- $memberAccountListId = $request->post('member_account_list_id');
- $status = $request->post('status');
- $password = $request->post('pay_pwd');
- if ($status == 'ACTIVED' && $password != '888666') {
- return json_fail('密码错误');
- }
- Db::beginTransaction();
- try {
- $withdraw = MemberAccountList::where('member_account_list_id', $memberAccountListId)->first();
- $withdraw->member_account_list_status = $status;
- $memberAccountListJson = [];
- if (!empty($withdraw->member_account_list_json)) {
- $memberAccountListJson = json_decode($withdraw->member_account_list_json, true);
- }
- if ($status == 'ACTIVED') {
- $memberAccountListJson['resulttime'] = date('Y-m-d H:i:s');
- // 扣账户余额
- $account = MemberAccount::where('join_account_member_id', $withdraw->join_member_account_list_member_id)
- ->where('member_account_classify', 'CASH')
- ->where('member_account_status', 'ACTIVED')
- ->first();
- if (empty($account)) {
- throw new BusinessException("账户异常");
- }
- if ($account->member_account_surplus < $withdraw->member_account_list_amount) {
- throw new BusinessException("账户余额不足");
- }
- $account->member_account_surplus = $account->member_account_surplus - $withdraw->member_account_list_amount;
- $account->member_account_expend = $account->member_account_expend + $withdraw->member_account_list_amount;
- $account->save();
- }
- $withdraw->save();
- _syslog('提现', '修改状态成功');
- Db::commit();
- if ($status == 'ACTIVED') {
- // 入收支记录
- $params['account_list_id'] = $memberAccountListId;
- $params['type'] = 'withdraw';
- Event::dispatch('statistics.inout.out',$params);
- }
- return json_success('success');
- } catch (BusinessException $e) {
- Db::rollBack();
- return json_fail($e->getMessage());
- } catch (\Exception $e) {
- Db::rollBack();
- return json_fail("修改状态失败");
- }
- }
- }
|