PerformanceLogic.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\api\logic;
  3. use app\common\enum\worker\WorkerAccountLogEnum;
  4. use app\common\logic\BaseLogic;
  5. use app\common\logic\EffectiveLogic;
  6. use app\common\logic\WorkerAccountLogLogic;
  7. use app\common\model\performance\PerformanceRules;
  8. use think\facade\Db;
  9. /**
  10. * 师傅业绩逻辑层
  11. * Class PerformanceLogic
  12. * @package app\api\logic
  13. */
  14. class PerformanceLogic extends BaseLogic
  15. {
  16. /**
  17. * @param $work
  18. * @return false|void
  19. */
  20. public static function calculatePerformance($work)
  21. {
  22. //工单已完结,进行结算,结算完成后设置work_pay_status为2,已结算
  23. $rule = PerformanceRules::whereFindInSet('goods_category_ids',$work->goods_category_id)->findOrEmpty();
  24. if($rule->isEmpty()){
  25. $work->work_pay_status = 3;
  26. }else{
  27. $work->work_pay_status = 2;
  28. }
  29. $work->save();
  30. //师傅金额结算
  31. if(!$rule->isEmpty()){
  32. if($rule['type']==0){
  33. $work_price = $work->work_total;
  34. }else{
  35. $work_price = $work->work_amount;
  36. }
  37. $settlement_amount = bcmul($work_price, $rule['rate']);
  38. WorkerAccountLogLogic::addAccountLog($work,$settlement_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
  39. }
  40. //生成保修卡
  41. EffectiveLogic::receiveEffective($work);
  42. }
  43. }