StoreBill.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\model\system;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. /**
  6. * 用户消费新增金额明细 model
  7. * Class User
  8. * @package app\admin\model\user
  9. */
  10. class StoreBill extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'store_bill';
  22. use ModelTrait;
  23. //修改积分减少积分记录
  24. public static function expend($title, $store_id, $type, $number, $link_id = 0, $balance = 0, $mark = '')
  25. {
  26. $pm = 0;
  27. $id = self::getkeytoid('bill_id');
  28. $add_time = date("Y-m-d H:i:s");
  29. return self::create(compact('title', 'store_id', 'link_id', 'type', 'number', 'balance', 'mark', 'pm', 'add_time', 'id'));
  30. }
  31. //修改积分增加积分记录
  32. public static function income($title, $store_id, $type, $number, $link_id = 0, $balance = 0, $mark = '')
  33. {
  34. $pm = 1;
  35. $id = self::getkeytoid('bill_id');
  36. $add_time = date("Y-m-d H:i:s");
  37. return self::create(compact('title', 'store_id', 'link_id', 'type', 'number', 'balance', 'mark', 'pm', 'add_time', 'id'));
  38. }
  39. public static function getBillList($where)
  40. {
  41. $whereModel = self::setWhereList($where);
  42. $count = $whereModel->count();
  43. $data = ($data = $whereModel->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  44. return compact('data', 'count');
  45. }
  46. public static function setWhereList($where)
  47. {
  48. $time['data'] = '';
  49. if ($where['start_time'] != '' && $where['end_time'] != '') {
  50. $time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
  51. }
  52. $model = self::getModelTime($time, self::alias('A')
  53. ->join('system_store B', 'B.id=A.store_id')
  54. ->order('A.add_time desc,A.id desc'), 'A.add_time');
  55. if (trim($where['type']) != '') {
  56. $model = $model->where('A.type', $where['type']);
  57. }
  58. if ($where['nickname'] != '') {
  59. $model = $model->where('B.name|B.id', 'like', "%$where[nickname]%");
  60. }
  61. if (isset($where['store_id']) && $where['store_id'] != '') {
  62. $model = $model->where('A.store_id', $where['store_id']);
  63. }
  64. return $model->field(['A.*', 'A.add_time', 'B.id', 'B.name']);
  65. }
  66. /**
  67. * 用户获得总佣金
  68. * @return float
  69. */
  70. public static function getBrokerageCount()
  71. {
  72. return self::where('pm', 1)->where('type', 'product_sale')->sum('number');
  73. }
  74. }