InvoiceRepository.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2018/12/25
  6. * Time: 18:19
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Invoice;
  10. use App\Models\InvoiceCategory;
  11. use Prettus\Repository\Criteria\RequestCriteria;
  12. use Prettus\Repository\Eloquent\BaseRepository;
  13. class InvoiceRepository extends BaseRepository
  14. {
  15. public $title_arr = [1=>'单位',2=>'个人'];
  16. public $cate = [1=>'咨询费',2=>'咨询服务费',3=>'服务费'];
  17. public function model()
  18. {
  19. return Invoice::class;
  20. }
  21. public function boot()
  22. {
  23. $this->pushCriteria(app(RequestCriteria::class));
  24. }
  25. public function getOne($order_id, $user)
  26. {
  27. $cate = $this->getCate();
  28. $cateaArr = array_column($cate, 'categoryname', 'id');
  29. $where['order_num'] = $order_id;
  30. $where['uid'] = $user->id;
  31. $info = $this->model->where($where)->first();
  32. if ($info) {
  33. $info->title = $this->title_arr[$info->title];
  34. $info->cate = $cateaArr[$info->cid];
  35. return $info;
  36. } else {
  37. return false;
  38. }
  39. }
  40. public function getOneInvoice($order_id, $user)
  41. {
  42. $where['order_num'] = $order_id;
  43. $where['uid'] = $user->id;
  44. return $this->model->where($where)->first();
  45. }
  46. public function getCate()
  47. {
  48. return InvoiceCategory::select(['id','categoryname'])->get()->toArray();
  49. }
  50. }