123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace app\admin\controller\member;
- use app\controller\Curd;
- use app\model\MemberAccount;
- use app\model\MemberBenefit;
- use support\exception\BusinessException;
- use support\Request;
- use Tinywan\Jwt\JwtToken;
- class AccountController extends Curd
- {
- public function __construct()
- {
- $this->model = new MemberAccount();
- }
- public function my($id)
- {
- $account = MemberAccount::where('join_account_member_id', $id)->get()->toArray();
- if (!$account) {
- // 账户表
- $accountData = [
- 'join_account_member_id' => $id,
- 'member_account_classify' => 'POINTS',
- 'member_account_status' => 'ACTIVED',
- 'member_account_category' => 'NORMAL',
- 'member_account_nbr' => $id . '-POINTS',
- 'member_account_name' => '积分账户',
- 'member_account_addtimes' => time()
- ];
- // 积分账户
- MemberAccount::insert($accountData);
- $accountData['member_account_classify'] = 'CASH';
- $accountData['member_account_nbr'] = $id . '-CASH';
- $accountData['member_account_name'] = '余额账户';
- // 现金/余额账户
- MemberAccount::insert($accountData);
- $account = MemberAccount::where('join_account_member_id', $id)->get()->toArray();
- }
- if ($account[0]['member_account_classify'] == 'POINTS') {
- $account = array_reverse($account);
- }
- foreach ($account as &$item) {
- $item['member_account_duedate'] = !empty($item['member_account_duedate']) ? date('Y-m-d H:i:s', $item['member_account_duedate']) : '长期有效';
- $item['member_account_surplus'] = round($item['member_account_surplus'] + $item['member_account_added'], 2);
- }
- return json_success('', $account);
- }
- public function incomeExpend(Request $request)
- {
- $params = $request->post();
- $account = MemberAccount::where('member_account_id', $params['member_account_id'])->first();
- if (!$account) {
- return json_fail('账户不存在');
- }
- try {
- if (!empty($params['type']) && $params['type'] == 'income') {
- $account->member_account_income = $account->member_account_income + $params['income'];
- $account->member_account_surplus = $account->member_account_surplus + $params['income'];
- $account->member_account_update_user_id = JwtToken::getCurrentId();
- $account->member_account_updatetimes = time();
- $account->save();
- } elseif (!empty($params['type']) && $params['type'] == 'expend') {
- $account->member_account_expend = $account->member_account_expend + $params['expend'];
- $account->member_account_surplus = $account->member_account_surplus - $params['expend'];
- $account->member_account_update_user_id = JwtToken::getCurrentId();
- $account->member_account_updatetimes = time();
- $account->save();
- }
- _syslog("账户出入账", $params['type'] == 'income' ? '入账' : '出账');
- return json_success("操作成功");
- } catch (\Exception $e) {
- return json_fail('操作失败');
- }
- }
- /**
- * 用户的账户
- */
- public function selectMemberAccount(Request $request)
- {
- $memberId = $request->get('member_id', '');
- if (!$memberId) {
- return json_fail('参数异常');
- }
- $account = MemberAccount::where('join_account_member_id', $memberId)->get()->toArray();
- $data = [];
- foreach ($account as $item) {
- $item['member_account_duedate'] = !empty($item['member_account_duedate']) ? date('Y-m-d H:i:s', $item['member_account_duedate']) : '长期有效';
- if ($item['member_account_classify'] == 'POINTS') {
- $data['points'] = $item;
- } elseif ($item['member_account_classify'] == 'CASH') {
- $data['cash'] = $item;
- } elseif ($item['member_account_classify'] == 'CARD') {
- $data['card'][] = $item;
- } elseif ($item['member_account_classify'] == 'WELFARE') {
- $data['welfare'] = $item;
- } elseif ($item['member_account_classify'] == 'VIP') {
- $data['vip'] = $item;
- }
- }
- return json_success('', $data);
- }
- /**
- * @Desc 修改账户状态
- * @Author Gorden
- * @Date 2024/9/12 16:28
- *
- * @param Request $request
- * @return \support\Response
- */
- public function updateStatus(Request $request)
- {
- $accountId = $request->post('account_id');
- $status = $request->post('status');
- if (!$accountId || !$status || !in_array($status,['DISABLED','ACTIVED','EXPIRED'])){
- return json_fail('参数异常');
- }
- try {
- $account = MemberAccount::where('member_account_id',$accountId)->first();
- $account->member_account_status = $status;
- $account->save();
- _syslog("修改账户状态",'修改账户状态成功');
- return json_success('账户状态修改成功');
- }catch (\Exception $e){
- _syslog("修改账户状态",'账户状态修改失败');
- return json_fail('账户状态修改失败');
- }
- }
- }
|