Pledge.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\ProductLists;
  5. use app\common\model\ProductOrder;
  6. use app\common\model\ProductPledges;
  7. use Exception;
  8. use app\api\logic\WelfareLoginc;
  9. use app\common\model\UserModel;
  10. use think\Db;
  11. use app\common\logic\PledgeLogic;
  12. //质押抵扣
  13. class Pledge extends Api
  14. {
  15. protected string $lan = '';
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->lan = $this->request->getLan();
  20. }
  21. //质押列表
  22. public function list(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
  23. {
  24. $type_id = $this->request->param('type_id', 0, 'intval');
  25. if(empty($type_id)) $this->error(__("参数有误,无可用产品"));
  26. $list = $productPledges
  27. ->where('status', $productPledges::Normal)
  28. ->where('to_lang', $this->lan)->where('type_id', $type_id)
  29. ->field('id,title,day_num,income_reta,product_id')
  30. ->order('weigh desc')
  31. ->paginate($this->pageSize);
  32. $list = $pledgeLogic::getByProductIdList($list, $this->lan);
  33. $this->success('', $list);
  34. }
  35. /*
  36. * 质押详情
  37. */
  38. public function detail(ProductPledges $productPledges, ProductLists $productList)
  39. {
  40. $id = $this->request->param('id', 0, 'intval');
  41. if(empty($id)) $this->error(__("参数有误,无可用产品"));
  42. //质押详情
  43. $pledges = $productPledges::get($id);
  44. if (!empty($pledges)) {
  45. $pledges->product_list = $productList::getBySynthesisProduct($pledges->product_id, $this->lan);
  46. }
  47. $this->success('', $pledges);
  48. }
  49. /*
  50. * 持有商品列表
  51. */
  52. public function holdProductList(PledgeLogic $pledgeLogic)
  53. {
  54. $product_id = $this->request->param('product_id', 0, 'intval');
  55. if(empty($product_id)) $this->error(__("参数有误,无可用产品"));
  56. $pledges = $pledgeLogic::getHoldProductList($this->auth->id, $product_id);
  57. $this->success('', $pledges);
  58. }
  59. /*
  60. * 质押存储
  61. */
  62. public function create(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
  63. {
  64. $pledge_id = $this->request->post('pledge_id', 0, 'intval');
  65. $order_no = $this->request->post('order_no/a', '');
  66. if(empty($pledge_id) || empty($order_no)) $this->error(__("参数有误,无可用产品"));
  67. $pledge = $productPledges::get($pledge_id);
  68. if(count(explode(',', $pledge->product_id)) || count($order_no)) $this->error(__("参数有误,无可用产品"));
  69. if (empty($pledge)) $this->error(__("质抵活动不存在"));
  70. if (empty($pledge->status) )$this->error(__("质抵活动已结束"));
  71. Db::startTrans();
  72. try {
  73. // 质抵押订单
  74. $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id);
  75. // 提交事务
  76. Db::commit();
  77. } catch (Exception $e) {
  78. // 回滚事务
  79. Db::rollback();
  80. $this->error($e->getMessage(), null, $e->getCode());
  81. }
  82. $this->success('ok');
  83. }
  84. /*
  85. * 我的茶矿
  86. */
  87. public function teamine(PledgeLogic $pledgeLogic)
  88. {
  89. try {
  90. // 质抵押订单
  91. $res = $pledgeLogic::getPledgeOrderList($this->auth->id);
  92. } catch (Exception $e) {
  93. $this->error($e->getMessage(), null, $e->getCode());
  94. }
  95. $this->success('ok', $res);
  96. }
  97. /*
  98. * 收取茶矿
  99. */
  100. public function collect(PledgeLogic $pledgeLogic)
  101. {
  102. Db::startTrans();
  103. try {
  104. // 质抵押订单
  105. $res = $pledgeLogic::getPledgeOrderList($this->auth->id);
  106. // 提交事务
  107. Db::commit();
  108. } catch (Exception $e) {
  109. // 回滚事务
  110. Db::rollback();
  111. $this->error($e->getMessage(), null, $e->getCode());
  112. }
  113. $this->success('ok', $res);
  114. }
  115. /*
  116. * 解除质押
  117. */
  118. public function remove(PledgeLogic $pledgeLogic)
  119. {
  120. $pledge_id = $this->request->post('pledge_id', 0, 'intval');
  121. if(empty($pledge_id)) $this->error(__("参数有误,无可用产品"));
  122. Db::startTrans();
  123. try {
  124. // 质抵押订单
  125. $res = $pledgeLogic::setPledgeRemove($pledge_id, $this->auth->id);
  126. // 提交事务
  127. Db::commit();
  128. } catch (Exception $e) {
  129. // 回滚事务
  130. Db::rollback();
  131. $this->error($e->getMessage(), null, $e->getCode());
  132. }
  133. $this->success('ok', $res);
  134. }
  135. }