123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?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;
- class AccountController extends Curd
- {
- public function __construct()
- {
- $this->model = new MemberAccount();
- }
- public function my($id)
- {
- $account = MemberAccount::where('join_account_member_id', $id)->where('member_account_status','ACTIVED')->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']) : '长期有效';
- }
- 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->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->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;
- }
- }
- return json_success('', $data);
- }
- }
|