12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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)->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('操作失败');
- }
- }
- }
|