ExpCost.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class ExpCost extends BaseModel
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. private $expCost;
  16. /**
  17. * 根据id查询平台
  18. * @param $id
  19. * @param string $field
  20. * @return mixed
  21. */
  22. public function getWareHouseExpCost($wId,$field = '*') {
  23. $tAr = [];
  24. if(!empty($this->expCost)) {
  25. foreach ($this->expCost as $v) {
  26. if ($v['warehouse_id'] == $wId) {
  27. $tAr[] = $field == '*' ? $v : $v[$field];
  28. }
  29. }
  30. }
  31. return $tAr;
  32. }
  33. /**
  34. * 平台数据
  35. * @return mixed|\think\Collection
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getExpCostData($sassid = 0,$level_id = 0){
  41. if(empty($this->expCost))
  42. $this->expCost = $this
  43. ->field("e.money,e.express_id,e.id,e.warehouse_id,exp.title,
  44. (SELECT name from table_warehouse where id = e.warehouse_id) as warehouse_name
  45. ")
  46. ->alias("e")
  47. ->join("express exp","exp.id = e.express_id")
  48. ->where('e.sassid',$sassid)
  49. ->where('e.level_id',$level_id)
  50. ->order("seq desc")
  51. ->select()
  52. ->toArray();
  53. // echo $this->getLastSql();
  54. return $this->expCost;
  55. }
  56. /**
  57. * 获取平台原价
  58. * @param int $express_id
  59. * @param int $warehouse_id
  60. * @param int $sassid
  61. * @return mixed
  62. */
  63. public function getSysExpCostPrice($express_id = 0, $warehouse_id = 0,$sassid = 0){
  64. $money = $this
  65. ->where('express_id',$express_id)
  66. ->where('warehouse_id',$warehouse_id)
  67. ->where('level_id',-1)
  68. ->where('sassid',$sassid)
  69. ->value('money');
  70. return $money;
  71. }
  72. /**
  73. * 分站价格佣金差价
  74. * @param $site
  75. * @param $parm
  76. */
  77. public function difference($site,$param) {
  78. //本级
  79. $money = $this->getSysExpCostPrice($param['express_id'],$param['warehouse_id'],$site['sassid']);
  80. //上级
  81. $money2 = $this->getSysExpCostPrice($param['express_id'],$param['warehouse_id'],$param['sassid']);
  82. if( empty($money) || empty($money2) || $money <= $money2) {
  83. return ;
  84. }
  85. $value = ($money - $money2) * $param['count'];
  86. (new SiteDetail)->difference($value,
  87. $param['sassid'],
  88. $param['orderid'],
  89. ['sitename' => $site['name'],
  90. 'user' => $param['user'],
  91. 'count' => $param['count'],
  92. 'money' => $value
  93. ]
  94. );
  95. }
  96. }