member_card.model.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=0);
  3. defined('InShopNC') or exit('Access Invalid!');
  4. use const mcard\STATE_OVER;
  5. use const mcard\STATE_UNSTART;
  6. use const mcard\STATE_USING;
  7. class member_cardModel extends Model
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct('member_card');
  12. }
  13. public function addCard($params)
  14. {
  15. return $this->insert($params);
  16. }
  17. public function disable($card_id)
  18. {
  19. return $this->where(['card_id' => $card_id])->update(['state' => 0]);
  20. }
  21. public function getCardInfo($card_id)
  22. {
  23. return $this->where(['card_id' => $card_id])->find();
  24. }
  25. public function getAllCards($member_id)
  26. {
  27. return $this->where(['member_id' => $member_id])->order('card_id asc')->select();
  28. }
  29. public function getUsableCards($member_id)
  30. {
  31. return $this->where(['member_id' => $member_id,'state' => ['in',[STATE_UNSTART,STATE_USING]]])
  32. ->order('card_id asc')
  33. ->select();
  34. }
  35. public function detuct($card_id,$cent,$useup)
  36. {
  37. if($useup) {
  38. $data['state'] = STATE_OVER;
  39. }
  40. $amount = round($cent / 100,2);
  41. $data['left_amount'] = ['exp', "left_amount-{$amount}"];
  42. return $this->where(['card_id' => $card_id])->update($data);
  43. }
  44. public function add_amound($card_id,$amount)
  45. {
  46. $data['state'] = STATE_USING;
  47. $amount = round($amount,2);
  48. $data['left_amount'] = ['exp', "left_amount+{$amount}"];
  49. return $this->where(['card_id' => $card_id])->update($data);
  50. }
  51. }