IncomeService.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\BrokerIncome as BrokerIncomeModel;
  4. use app\common\model\Broker as BrokerModel;
  5. use app\common\model\Config;
  6. use app\common\model\Worker as WorkerModel;
  7. use app\common\model\Agent as AgentModel;
  8. class IncomeService extends BaseService
  9. {
  10. public function add($broker_id, $value, $title, $remark = '')
  11. {
  12. if (empty($value)) {
  13. return false;
  14. }
  15. if (empty($broker_id)) {
  16. $broker_id = Config::getConfigValue('default_broker');
  17. }
  18. $broker = BrokerModel::where('id', $broker_id)->find();
  19. $income = new BrokerIncomeModel();
  20. $income->save([
  21. 'brokerid' => $broker_id,
  22. 'workerid' => $broker['workerid'],
  23. 'agentid' => $broker['agentid'],
  24. 'title' => $title,
  25. 'origin_value' => $broker['income'],
  26. 'value' => $value,
  27. 'remark' => $remark,
  28. 'createtime' => time(),
  29. 'yeartime' => date("Y"),
  30. 'monthtime' => date("Ym"),
  31. ]);
  32. //修改收益
  33. $worker = WorkerModel::where('id', $broker['workerid'])->find();
  34. $worker->income += $value;
  35. $agent = AgentModel::where('id', $broker['agentid'])->find();
  36. $agent->income += $value;
  37. $broker->income += $value;
  38. //修改累计收益
  39. if ($value > 0) {
  40. $broker->income_total += $value;
  41. $worker->income_total += $value;
  42. $agent->income_total += $value;
  43. }
  44. $broker->save();
  45. $worker->save();
  46. $agent->save();
  47. }
  48. }