Award.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\api\model\taxi;
  3. use app\api\model\user\MotorAgent;
  4. use app\common\model\BaseModel;
  5. use app\common\model\TaxiOrder;
  6. use think\db\Query;
  7. use think\Exception;
  8. use think\Model;
  9. class Award extends BaseModel
  10. {
  11. public function send(Model $order)
  12. {
  13. $MotorAgent = new MotorAgent();
  14. $MotorRecord = new MotorRecord();
  15. $result = false;
  16. $this->startTrans();
  17. try {
  18. $percent = sys_config('agent_share', 'agent');
  19. $motorAgent = $MotorAgent->with([
  20. 'user'
  21. ])
  22. ->where('area_id', $order['area_id'])
  23. ->find();
  24. if ($motorAgent) {
  25. $money = bcmul($order['price'], $percent/100, 2);
  26. $motorAgent->user->motor_agent_money += $money;
  27. $motorAgent->user->save();
  28. $MotorRecord->setMoneyLog($motorAgent->user, 'motor_agent_money', $money, 0, '摩的代理分红');
  29. $result = $MotorRecord->saveMoneyLog();
  30. }
  31. $this->commit();
  32. }
  33. catch(Exception $e) {
  34. $this->rollback();
  35. throw new Exception($e->getMessage());
  36. }
  37. return $result;
  38. }
  39. }