| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\ProductLists;
- use app\common\model\ProductOrder;
- use app\common\model\ProductPledges;
- use Exception;
- use app\common\model\UserModel;
- use think\Db;
- use app\common\logic\PledgeLogic;
- //质押抵扣
- class Pledge extends Api
- {
- protected string $lan = '';
- public function _initialize()
- {
- parent::_initialize();
- $this->lan = $this->request->getLan();
- }
- //质押列表
- public function list(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
- {
- $type_id = $this->request->param('type_id', 0, 'intval');
- if(empty($type_id)) $this->error(__("参数有误,无可用产品"));
- $list = $productPledges
- ->where('status', $productPledges::Normal)
- ->where('to_lang', $this->lan)->where('type_id', $type_id)
- ->field('id,title,day_num,income_reta,product_id')
- ->order('weigh desc')
- ->paginate($this->pageSize);
- $list = $pledgeLogic::getByProductIdList($list, $this->lan);
- $this->success('', $list);
- }
- /*
- * 质押详情
- */
- public function detail(ProductPledges $productPledges, ProductLists $productList)
- {
- $id = $this->request->param('id', 0, 'intval');
- if(empty($id)) $this->error(__("参数有误,无可用产品"));
- //质押详情
- $pledges = $productPledges::get($id);
- if (!empty($pledges)) {
- $pledges->product_list = $productList::getBySynthesisProduct($pledges->product_id, $this->lan);
- }
- $this->success('', $pledges);
- }
- /*
- * 持有商品列表
- */
- public function holdProductList(PledgeLogic $pledgeLogic)
- {
- $product_id = $this->request->param('product_id', 0, 'intval');
- if(empty($product_id)) $this->error(__("参数有误,无可用产品"));
- $pledges = $pledgeLogic::getHoldProductList($this->auth->id, $product_id);
- $this->success('', $pledges);
- }
- /*
- * 质押存储
- */
- public function create(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
- {
- $pledge_id = $this->request->post('pledge_id', 0, 'intval');
- $order_no = $this->request->post('order_no/a', '');
- if(empty($pledge_id) || empty($order_no)) $this->error(__("参数有误,无可用产品"));
- $pledge = $productPledges::get($pledge_id);
- if($pledge->type_id == $productPledges::Combin && count(explode(',', $pledge->product_id)) != count($order_no)) $this->error(__("质押商品数量与订单数量不匹配"));
- if (empty($pledge)) $this->error(__("质抵活动不存在"));
- if (empty($pledge->status) )$this->error(__("质抵活动已结束"));
- Db::startTrans();
- try {
- // 质抵押订单
- $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id);
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->error($e->getMessage(), null, $e->getCode());
- }
- $this->success('ok');
- }
-
- /*
- * 我的茶矿
- */
- public function teamine(PledgeLogic $pledgeLogic)
- {
- try {
- // 质抵押订单
- $res = $pledgeLogic::getPledgeOrderList($this->auth->id);
- } catch (Exception $e) {
-
- $this->error($e->getMessage(), null, $e->getCode());
- }
- $this->success('ok', $res);
- }
- /*
- * 收取茶矿
- */
- public function collect(PledgeLogic $pledgeLogic)
- {
- //if($pledgeLogic::getCheckRequestApi('collect', $this->auth->id, 300) == false) $this->error(__("收取太pio啦,请稍后再试"));
- Db::startTrans();
- try {
- // 质抵押订单
- $res = $pledgeLogic::getPledgeCollect($this->auth->id);
- //请求限制
- cache('collect_'.$this->auth->id, time(), 300);
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->error($e->getMessage(), null, $e->getCode());
- }
- $this->success('ok', $res);
- }
- /*
- * 解除质押
- */
- public function remove(PledgeLogic $pledgeLogic)
- {
- $pledge_id = $this->request->post('pledge_id', 0, 'intval');
- if(empty($pledge_id)) $this->error(__("参数有误,无可用产品"));
- Db::startTrans();
- try {
- // 质抵押订单
- $res = $pledgeLogic::setPledgeRemove($pledge_id, 1275);
-
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->error($e->getMessage(), null, $e->getCode());
- }
- $this->success('ok', $res);
- }
-
-
- }
|