StoreRechargeCardBrokerage.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\models\store;
  3. use crmeb\services\UtilService;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. class StoreRechargeCardBrokerage extends BaseModel
  7. {
  8. /**
  9. * 数据表主键
  10. * @var string
  11. */
  12. protected $pk = 'id';
  13. /**
  14. * 模型名称
  15. * @var string
  16. */
  17. protected $name = 'store_recharge_card_brokerage';
  18. use ModelTrait;
  19. public static function merSet($mer_id, $alias = '')
  20. {
  21. return $mer_id ? self::where($alias ? $alias . '.mer_id' : 'mer_id', $mer_id) : new self;
  22. }
  23. protected function getAddTimeAttr($value)
  24. {
  25. if ($value) return date('Y-m-d H:i:s', $value);
  26. return '';
  27. }
  28. /**
  29. * 充值卡列表
  30. * @param $where
  31. * @return array
  32. */
  33. public static function systemPage($where)
  34. {
  35. $model = self::setWhere($where);
  36. $count = $model->count();
  37. $list = $model->page((int)$where['page'], (int)$where['limit'])
  38. ->select();
  39. return compact('count', 'list');
  40. }
  41. /**
  42. * 设置充值卡 where 条件
  43. * @param $where
  44. * @param null $model
  45. * @return mixed
  46. */
  47. public static function setWhere($where, $model = null)
  48. {
  49. $model = $model === null ? new self() : $model;
  50. $model = $model->where('mer_id', $where['mer_id']);
  51. return $model->order('id desc')->where('is_del', 0);
  52. }
  53. /**
  54. * 新增或编辑充值卡返现比例
  55. */
  56. public static function saveRechargeCardBrokerage($indata, $cid)
  57. {
  58. foreach($indata as $value){
  59. if(!$value){
  60. return $this->fail('请输入正确的返现比例');
  61. }
  62. if(!empty($value['id'])){
  63. $ids[] = $value['id'];
  64. self::edit($value, $value['id']);
  65. }else{
  66. $ids[] = self::insertGetId($value);
  67. }
  68. }
  69. $data[] = ['id', 'not in', $ids];
  70. $data[] = ['cid', '=', $cid];
  71. $overs = self::where($data)->select();
  72. foreach($overs as $over){
  73. self::destroy($over['id']);
  74. }
  75. }
  76. }