12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- declare(strict_types=0);
- defined('InShopNC') or exit('Access Invalid!');
- use const mcard\STATE_OVER;
- use const mcard\STATE_UNSTART;
- use const mcard\STATE_USING;
- class member_cardModel extends Model
- {
- public function __construct()
- {
- parent::__construct('member_card');
- }
- public function addCard($params)
- {
- return $this->insert($params);
- }
- public function disable($card_id)
- {
- return $this->where(['card_id' => $card_id])->update(['state' => 0]);
- }
- public function getCardInfo($card_id)
- {
- return $this->where(['card_id' => $card_id])->find();
- }
- public function getAllCards($member_id)
- {
- return $this->where(['member_id' => $member_id])->order('card_id asc')->select();
- }
- public function getUsableCards($member_id)
- {
- return $this->where(['member_id' => $member_id,'state' => ['in',[STATE_UNSTART,STATE_USING]]])
- ->order('card_id asc')
- ->select();
- }
- public function detuct($card_id,$cent,$useup)
- {
- if($useup) {
- $data['state'] = STATE_OVER;
- }
- $amount = round($cent / 100,2);
- $data['left_amount'] = ['exp', "left_amount-{$amount}"];
- return $this->where(['card_id' => $card_id])->update($data);
- }
- public function add_amound($card_id,$amount)
- {
- $data['state'] = STATE_USING;
- $amount = round($amount,2);
- $data['left_amount'] = ['exp', "left_amount+{$amount}"];
- return $this->where(['card_id' => $card_id])->update($data);
- }
- }
|