AgentMoney.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. /**
  5. *
  6. */
  7. class AgentMoney extends BaseModel {
  8. protected $table = 'agent_money';
  9. public $timestamps = false;
  10. //插入代理流水
  11. function insertData($data){
  12. $res=$this->insert($data);
  13. if(!$res){
  14. return -8070000122;//添加流水记录失败
  15. }
  16. return 1;
  17. }
  18. //获取代理流水列表
  19. function getMoneyList($where,$list=20){
  20. // DB::connection()->enableQueryLog();
  21. $model=$this;
  22. if(!empty($where)&&count($where)>0){
  23. $model=$model->where($where);
  24. }
  25. $model=$model->orderBy('id','desc');
  26. $data=$model->paginate($list);
  27. // $queries = DB::getQueryLog();
  28. // print_r($queries);
  29. if(!$data){
  30. return -8031234;
  31. }
  32. return $data->toArray();
  33. }
  34. //id=>setle结算金额
  35. protected function Settle(){
  36. $data=$this->select(DB::raw('SUM(money) as money,agent_identity'))->groupBy('agent_identity')->get();
  37. if(!$data){
  38. return -803233;
  39. }
  40. $data=$data->toArray();
  41. $arr=array();
  42. foreach ($data as $v){
  43. $arr[$v['agent_identity']]=$v['money'];
  44. }
  45. return $arr;
  46. }
  47. }
  48. ?>