Bill.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\service;
  3. use app\service\ConfServiceFacade;
  4. use app\service\api\UserServiceFacade;
  5. use laytp\traits\Error;
  6. use think\facade\Cache;
  7. use think\facade\Config;
  8. use think\facade\Request;
  9. use EasyWeChat\Factory;
  10. use think\facade\Db;
  11. class Bill
  12. {
  13. use Error;
  14. /**
  15. * phpmailer对象
  16. */
  17. protected $client;
  18. /**
  19. * 构造函数
  20. */
  21. public function __construct()
  22. {
  23. // $conf = ConfServiceFacade::groupGet('system.ai');
  24. // $this->client = new \AipOcr($conf['app_id'],$conf['api_key'],$conf['secret_key']);
  25. }
  26. /**
  27. * 初始化
  28. * @param $token
  29. * @return bool
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function record($pm=0,$coin=0,$type = '',$mark = '',$uid = '',$uniacid = '',$direct=false,$balance=0,$isTime=0)
  35. {
  36. $model = new \app\model\Bill();
  37. $payPrice = 0;
  38. $post['pm'] = $pm ;
  39. $post['coin'] = $coin;
  40. $post['type'] = $type;
  41. $post['mark'] = $mark;
  42. $post['uid'] = $uid;
  43. $post['uniacid'] = $uniacid;
  44. $post['is_time'] = $isTime;
  45. if($direct){
  46. $balance = $balance;
  47. }else{
  48. $loginUserInfo = \app\model\User::where('id','=',$uid)->find();
  49. $money = $loginUserInfo['coin'];
  50. // 更新用户余额
  51. if($pm == 0){
  52. $balance = $money-$coin;
  53. }else{
  54. $balance = $money+$coin;
  55. }
  56. }
  57. $post['balance'] = $balance;
  58. Db::startTrans();
  59. try{
  60. $saveRes = $model->save($post);
  61. if (!$saveRes) throw new \Exception('保存基础信息失败');
  62. Db::commit();
  63. return true;
  64. }catch (\Exception $e) {
  65. Db::rollback();
  66. $this->setError('数据库异常,操作失败');
  67. return false;
  68. }
  69. }
  70. }