OaAgentModel.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * OaAgentModel.php UTF-8
  4. * 推广员每日业绩表
  5. *
  6. * @date : 2018/07/20 22:47
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : guxiannong <gxn@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\oa;
  13. use huo\model\common\CommonModel;
  14. use huo\model\game\GameModel;
  15. use huo\model\user\UserModel;
  16. class OaAgentModel extends CommonModel {
  17. protected $name = 'oa_agent';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. public function agent() {
  21. return $this->belongsTo(UserModel::className(), 'agent_id', 'id')->field('id,user_login,role_id');
  22. }
  23. public function game() {
  24. return $this->belongsTo(GameModel::className(), 'app_id', 'id')->field('id,name');
  25. }
  26. /**
  27. * 获取列表
  28. *
  29. * @param array $param
  30. * @param int $offset
  31. * @param bool $get_sum
  32. *
  33. * @return array|false|\PDOStatement|string|\think\Model|\think\Paginator
  34. */
  35. public function getAgentDateList($param = array(), $offset = 10, $get_sum = false) {
  36. $_offset = isset($param['list_rows']) ? $param['list_rows'] : $offset;
  37. $_order = isset($param['list_order']) ? $param['list_order'] : 'id desc';
  38. $_map = array();
  39. if (isset($param['app_id']) && !empty($param['app_id'])) {
  40. $_map['app_id'] = $param['app_id'];
  41. }
  42. if (isset($param['agent_id']) && !empty($param['agent_id'])) {
  43. $_map['agent_id'] = $param['agent_id'];
  44. }
  45. if (isset($param['date']) && !empty($param['date'])) {
  46. $_map['date'] = $param['date'];
  47. }
  48. if (isset($param['is_standard']) && !empty($param['is_standard'])) {
  49. $_map['is_standard'] = $param['is_standard'];
  50. }
  51. $_field = 'id,date,agent_id,app_id,reg_cnt,reg_ip_cnt,standard_mem_cnt,order_cnt,pay_mem_cnt,sum_money';
  52. $_field .= ',is_standard,create_time,update_time';
  53. $_list_field = isset($param['list_field']) ? $param['list_field'] : $_field;
  54. if ($get_sum) {
  55. $_sum_field
  56. = ' sum(reg_cnt) as reg_cnt, sum(reg_ip_cnt) as reg_ip_cnt,sum(standard_mem_cnt) as standard_mem_cnt';
  57. $_sum_field .= ',sum(order_cnt) as order_cnt,sum(pay_mem_cnt) as pay_mem_cnt,sum(sum_money) as sum_money,count(*) as all_count';
  58. $_list_field = isset($param['list_field']) ? $param['list_field'] : $_sum_field;
  59. $_data = $this
  60. ->field($_list_field)
  61. ->where($_map)
  62. ->find();
  63. } else {
  64. $_data = $this
  65. ->field($_list_field)
  66. ->where($_map)
  67. ->order($_order)
  68. ->paginate($_offset);
  69. }
  70. return $_data;
  71. }
  72. }