Provider.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\store\model;
  4. use app\common\model\Provider as ProviderModel;
  5. use app\store\model\OrderGoods as OrderGoodsModel;
  6. /**
  7. * 供应商模型
  8. * Class Provider
  9. * @package app\common\model
  10. */
  11. class Provider extends ProviderModel
  12. {
  13. public function getProviderList($params){
  14. $model = $this->field('provider_id,provider_name,th_province_id,th_city_id,th_region_id,th_address')
  15. ->withCount(['orderGoodsWait'=>function($query){
  16. //$query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_WAIT);
  17. //v1.2 待结算通过结算时间判断
  18. $query->where('provider_settlement_time','>',0)
  19. ->where('provider_settlement_time','<',time())
  20. ->where('finance_clearing_status','=',OrderGoods::FINANCE_CLEARING_WAIT);
  21. }])->withCount(['orderGoodsDone'=>function($query){
  22. $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_DONE);
  23. }])->withCount(['orderGoodsFreeze'=>function($query){
  24. $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_FREEZE);
  25. }]);
  26. if ($params){
  27. $model = $model->whereLike('provider_name','%'.$params.'%');
  28. }
  29. return $model->order('provider_id','desc')->paginate(15)->toArray();
  30. }
  31. public function orderGoodsWait(){
  32. return $this->hasMany(OrderGoods::class,'provider_id','provider_id');
  33. }
  34. public function orderGoodsDone(){
  35. return $this->hasMany(OrderGoods::class,'provider_id','provider_id');
  36. }
  37. public function orderGoodsFreeze(){
  38. return $this->hasMany(OrderGoods::class,'provider_id','provider_id');
  39. }
  40. public function orderGoods(){
  41. return $this->hasMany(OrderGoods::class,'provider_id','provider_id');
  42. }
  43. /**
  44. * 导出待结算的供应商列表
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function providersExport($params){
  51. $model = $this->field('provider_id,provider_name,th_province_id,th_city_id,th_region_id,th_address')
  52. ->withCount(['orderGoodsWait'=>function($query){
  53. //v1.2 待结算通过结算时间判断
  54. $query->where('provider_settlement_time','>',0)
  55. ->where('provider_settlement_time','<',time())
  56. ->where('finance_clearing_status','=',OrderGoods::FINANCE_CLEARING_WAIT);
  57. }])->withCount(['orderGoodsDone'=>function($query){
  58. $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_DONE);
  59. }])->withCount(['orderGoodsFreeze'=>function($query){
  60. $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_FREEZE);
  61. }]);
  62. if ($params){
  63. $model = $model->whereLike('provider_name','%'.$params.'%');
  64. }
  65. $list = $model->order('provider_id','desc')->select()->toArray();
  66. $data['header'] = ['序号', '供应商名称', '待结算', '已结算', '冻结中','待结算金额'];
  67. $data['filename'] = '供应商结算列表导出';
  68. $data['data'] = [];
  69. foreach ($list as $arr){
  70. $new_list['provider_id'] = $arr['provider_id'];
  71. $new_list['provider_name'] = $arr['provider_name'];
  72. $new_list['wait_count'] = $arr['order_goods_wait_count'];
  73. $new_list['done_count'] = $arr['order_goods_done_count'];
  74. $new_list['freeze_count'] = $arr['order_goods_freeze_count'];
  75. $new_list['wait_clearing_money'] = OrderGoodsModel::waitClearingMoney($arr['provider_id']);
  76. $data['data'][] = $new_list;
  77. }
  78. return $data;
  79. }
  80. }