Ensure.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\api\model\service\SkillEnsurePay;
  4. use app\common\controller\Api;
  5. use addons\service\library\Pay;
  6. use fast\Random;
  7. use think\Db;
  8. /**
  9. * 首页接口
  10. */
  11. class Ensure extends Api
  12. {
  13. protected $noNeedLogin = [''];
  14. protected $noNeedRight = ['*'];
  15. /**
  16. * 服务员缴纳保证金
  17. * @return void
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. * @throws \think\exception\DbException
  21. */
  22. public function skillEnsure()
  23. {
  24. $uid = $this->auth->id;
  25. $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,is_skill,is_shop')->find();
  26. $type = input('type','');
  27. if($type == 'pay')
  28. {
  29. if (!$this->request->isPost()) {
  30. $this->error('请求方式异常');
  31. }
  32. $userInfo['is_skill'] != 1 && $this->error('非服务者无法支付保证金');
  33. $id = input('id/d','');
  34. $paytype = input('paytype/d',0);
  35. $price = sprintf("%.2f",input('price',''));
  36. $orderId = 'SkillEn'.Random::alnum(4).'-'.$uid.'-'.time();
  37. $re = '';
  38. Db::startTrans();
  39. try{
  40. $skillEnsurePay = new \app\api\model\service\SkillEnsurePay(['user_id'=>$uid,'price'=>$price,'orderId'=>$orderId,'paytype'=>$paytype]);
  41. $skillEnsurePay->allowField(true)->save();
  42. if($price > 0)
  43. {
  44. $re = \addons\service\library\Pay::payOrder(['amount'=>$price,'orderid'=>$orderId,'title'=>'充值保证金'],$paytype,$uid,1);
  45. }else{
  46. \app\api\model\service\SkillEnsurePay::where(['id'=>$skillEnsurePay->id])->update(['state'=>1,'paytime'=>time()]);
  47. \app\api\model\service\SkillEnsurePay::updateSkillEnsure($uid,$price);
  48. }
  49. Db::commit();
  50. } catch (Exception $e) {
  51. Db::rollback();
  52. $this->error('支付拉起失败',$e->getMessage());
  53. }
  54. $this->success('支付信息返回成功',$re);
  55. }
  56. $list = model('app\api\model\service\SkillEnsure')->field('id,name,price,accept_nums')->order('price asc')->select();
  57. $this->success('信息返回成功',$list);
  58. }
  59. /**
  60. * 服务人员充值保证金记录
  61. * @return void
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @throws \think\exception\DbException
  65. */
  66. public function skillEnsurePayList()
  67. {
  68. $uid = $this->auth->id;
  69. $page = input('page/d',1);
  70. $list = model('app\api\model\service\SkillEnsurePay')
  71. ->where(['user_id'=>$uid,'state'=>1])
  72. ->order('id desc')
  73. ->page($page)
  74. ->limit(10)
  75. ->select();
  76. $this->success('信息返回成功',$list);
  77. }
  78. /**
  79. * 商户充值保证金记录
  80. * @return void
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. */
  85. public function shopEnsurePayList()
  86. {
  87. $uid = $this->auth->id;
  88. $page = input('page/d',1);
  89. $list = model('app\api\model\service\ShopEnsurePay')
  90. ->where(['user_id'=>$uid,'state'=>1])
  91. ->order('id desc')
  92. ->page($page)
  93. ->limit(10)
  94. ->select();
  95. $this->success('信息返回成功',$list);
  96. }
  97. public function ensureLog()
  98. {
  99. if (!$this->request->isPost()) {
  100. $this->error('请求方式异常');
  101. }
  102. $uid = $this->auth->id;
  103. $type = input('type/d',0);
  104. $page = input('page/d',1);
  105. $list = \app\api\model\service\EnsureLog::where(['user_id'=>$uid,'type'=>$type])->field('money,memo,createtime')->order('id desc')->page($page)->limit(10)->select();
  106. $this->success('信息返回成功',$list);
  107. }
  108. /**
  109. * 商家缴纳保证金
  110. * @return void
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\ModelNotFoundException
  113. * @throws \think\exception\DbException
  114. */
  115. public function shopEnsure()
  116. {
  117. if (!$this->request->isPost()) {
  118. $this->error('请求方式异常');
  119. }
  120. $uid = $this->auth->id;
  121. $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,is_skill,is_shop')->find();
  122. $type = input('type','');
  123. if($type == 'pay')
  124. {
  125. $userInfo['is_shop'] != 1 && $this->error('非商家无法支付保证金');
  126. $id = input('id/d','');
  127. $paytype = input('paytype/d',0);
  128. $price = sprintf("%.2f",input('price',''));
  129. $orderId = 'ShopEn'.Random::alnum(4).'-'.$uid.'-'.time();
  130. $re = '';
  131. Db::startTrans();
  132. try{
  133. $shopEnsurePay = new \app\api\model\service\ShopEnsurePay(['user_id'=>$uid,'price'=>$price,'orderId'=>$orderId,'paytype'=>$paytype]);
  134. $shopEnsurePay->allowField(true)->save();
  135. if($price > 0)
  136. {
  137. $re = \addons\service\library\Pay::payOrder(['amount'=>$price,'orderid'=>$orderId,'title'=>'充值保证金'],$paytype,$uid,2);
  138. }else{
  139. \app\api\model\service\ShopEnsurePay::where(['id'=>$shopEnsurePay->id])->update(['state'=>1,'paytime'=>time()]);
  140. \app\api\model\service\ShopEnsurePay::updateShopEnsure($uid,$price);
  141. }
  142. Db::commit();
  143. } catch (Exception $e) {
  144. Db::rollback();
  145. $this->error('支付拉起失败',$e->getMessage());
  146. }
  147. $this->success('支付信息返回成功',$re);
  148. }
  149. $list = model('app\api\model\service\ShopEnsure')->field('id,name,price,accept_nums,service_nums')->order('price asc')->select();
  150. $this->success('信息返回成功',$list);
  151. }
  152. }