Pledge.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 (empty($pledge)) $this->error(__("合成活动不存在"));
  69. if (empty($pledge->status) )$this->error(__("合成活动已结束"));
  70. Db::startTrans();
  71. try {
  72. // 质抵押订单
  73. $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id);
  74. // 提交事务
  75. Db::commit();
  76. } catch (Exception $e) {
  77. // 回滚事务
  78. Db::rollback();
  79. $this->error($e->getMessage(), null, $e->getCode());
  80. }
  81. $this->success('ok');
  82. }
  83. /*
  84. * 我的茶矿
  85. */
  86. public function teamine(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
  87. {
  88. Db::startTrans();
  89. try {
  90. // 质抵押订单
  91. $res = $pledgeLogic::getPledgeOrderList(1275);
  92. // 提交事务
  93. Db::commit();
  94. } catch (Exception $e) {
  95. // 回滚事务
  96. Db::rollback();
  97. $this->error($e->getMessage(), null, $e->getCode());
  98. }
  99. $this->success('ok', $res);
  100. }
  101. }