123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\api\controller\card\number;
- use app\api\controller\Api;
- /**
- * 账单
- */
- class Bill extends Api{
- protected $CardNumberBill = null;
- protected function init(){
- parent::init();
- $this->CardNumberBill = model('card.number.bill');
- }
- public function add(){
- $no = input('param.cardNo');
- if (empty($no)) {
- $this->output(1,'卡号不能为空');
- }
- $member_id = input('param.memberId');
- $CardNumber = model('card.Number');
- $number = $CardNumber->where(['no'=>$no,'member_id'=>$member_id])->find();
- if (!$number) {
- $this->output(1,'未找到该卡');
- }
- $amount = input('param.amount');
- $amount = floatval($amount);
- if ($amount > 0) {
- if ($number['balance'] < $amount) {
- $this->output(1,'卡余额不足');
- }
- }
- $this->CardNumberBill->startTrans();
- $number['balance'] -= $amount;
- $result = $number->save();
- if (!$result) {
- $this->CardNumberBill->rollback();
- $this->output(1,'保存失败');
- }
- $this->CardNumberBill->card_id = $number['card_id'];
- $this->CardNumberBill->number_id = $number['id'];
- $this->CardNumberBill->member_id = $member_id;
- $this->CardNumberBill->amount = $amount * -1;
- $this->CardNumberBill->order_no = input('param.orderNo');
- $this->CardNumberBill->is_vir = input('param.is_vir');
- $result = $this->CardNumberBill->save();
- if (!$result) {
- $this->CardNumberBill->rollback();
- $this->output(1,'保存失败');
- }
- $this->CardNumberBill->commit();
- $this->output(0,'保存成功');
- }
- }
|