UserHonor_Share.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * 下单行为类.
  4. * User: qissen
  5. * Date: 2018/2/19
  6. * Time: 13:59
  7. */
  8. namespace app\mobile\behavior;
  9. use app\core\model\Cash;
  10. use app\core\model\Cang;
  11. use app\core\model\UserAccount;
  12. use app\core\service\Finance;
  13. use think\Db;
  14. use think\Exception;
  15. use think\Log;
  16. class UserHonor_Share
  17. {
  18. //下单成功
  19. public function run(&$params)
  20. {
  21. Log::write('UserHonor', 'behavior');
  22. return true;
  23. // 行为逻辑
  24. $cang = $params['cang'];
  25. $user = $params['user'];
  26. $money = '10';
  27. $fromUserAccount = '17316900863';
  28. Db::startTrans();
  29. try{
  30. //第一步
  31. $finance = new Finance();
  32. $trade = new \Trade();
  33. $trade->setPayment($fromUserAccount);
  34. $trade->setReceive($user['mobile']);
  35. $trade->setMoney($money);
  36. $trade->setRem('现金鼓励');
  37. $result = $finance->order($msg, $trade);
  38. if(!$result) {
  39. Db::rollback();
  40. return true;
  41. }
  42. //第二步
  43. $cash = Cash::create([
  44. 'mode'=>Cash::MODE_CANG,
  45. 'modeID'=>$cang['cangID'],
  46. 'outerNumber'=>$result,
  47. 'userID'=>$user['userID'],
  48. 'fromUser'=>$fromUserAccount,
  49. 'money'=>$money
  50. ]);
  51. //第三步
  52. $user->userAccount = $user->userAccount->MODE_cashsend_addMoney($cash, $user);
  53. Db::commit();
  54. }
  55. catch (Exception $e) {
  56. Log::write($e->getMessage().'|'.$e->getLine().'|'.$e->getFile(), 'behavior');
  57. Db::rollback();
  58. }
  59. return true;
  60. }
  61. }