123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace JinDouYun\Controller\Commission;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Commission\MCommissionCalculate;
- use JinDouYun\Model\Commission\MCommissionGoods;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- /**
- * 分销商品控制器
- * Description:
- * Class CommissionGoods
- */
- class CommissionGoods extends BaseController
- {
- /**
- * @var MCommissionGoods
- */
- private $objMCommissionGoods;
- /**
- * CommissionGoods constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @param bool $checkToken
- * @param bool $getAreaCode
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
- $this->objMCommissionGoods = new MCommissionGoods($this->onlineEnterpriseId,$this->onlineUserId);
- }
- public function __destruct()
- {
- // TODO: Implement __destruct() method.
- }
- /**
- * Doc: (des="分销商品列表")
- * User: XMing
- * Date: 2020/7/22
- * Time: 11:56 上午
- */
- public function getAll()
- {
- $params = $this->request->getRawJson();
- $page = isset($params['page']) ? $params['page'] : 1;
- $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
- $offset = ($page - 1) * $pageSize;
- $params['limit'] = $pageSize;
- $params['offset'] = $offset;
- $dbResult = $this->objMCommissionGoods->getAll($params);
- if ($dbResult->isSuccess()) {
- $returnData = $dbResult->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total']
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
- }
- /**
- * Doc: (des="设置商品佣金")
- * User: XMing
- * Date: 2020/7/22
- * Time: 12:20 下午
- * @example {"id":131,"isDefine":5,"isJoinCommission":5,"commission_rule":[{"skuId":1036,"rule":{"0":{"oneRate":1,"twoRate":2,"threeRate":3},"2":{"oneRate":4,"twoRate":5,"threeRate":6},"3":{"oneRate":7,"twoRate":8,"threeRate":9},"4":{"oneRate":10,"twoRate":11,"threeRate":12}}},{"skuId":1037,"rule":{"0":{"oneRate":1,"twoRate":2,"threeRate":3},"2":{"oneRate":4,"twoRate":5,"threeRate":6},"3":{"oneRate":7,"twoRate":8,"threeRate":9},"4":{"oneRate":10,"twoRate":11,"threeRate":12}}},{"skuId":1038,"rule":{"0":{"oneRate":1,"twoRate":2,"threeRate":3},"2":{"oneRate":4,"twoRate":5,"threeRate":6},"3":{"oneRate":7,"twoRate":8,"threeRate":9},"4":{"oneRate":10,"twoRate":11,"threeRate":12}}}]}
- */
- public function setCommission()
- {
- $params = $this->request->getRawJson();
- $data = [
- 'id' => isset($params['id']) ? $params['id'] : null,
- 'isDefine' => isset($params['isDefine']) ? $params['isDefine'] : null,
- 'retType' => isset($params['retType']) ? $params['retType'] : StatusCode::$delete,
- 'isJoinCommission' => isset($params['isJoinCommission']) ? $params['isJoinCommission'] : null
- ];
- foreach ($data as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['commission_rule'] = isset($params['commission_rule']) ? $params['commission_rule'] : null;
- $result = $this->objMCommissionGoods->setCommission($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="分销商品详情")
- * User: XMing
- * Date: 2020/7/22
- * Time: 12:03 下午
- */
- public function getInfo()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMCommissionGoods->getInfo($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="商品批量设置是否参与分销")
- * User: XMing
- * Date: 2020/7/22
- * Time: 12:25 下午
- */
- public function updateIsJoin()
- {
- $params = $this->request->getRawJson();
- $data = [
- 'id' => isset($params['id']) ? $params['id'] : null,
- 'isJoinCommission' => isset($params['isJoinCommission']) ? $params['isJoinCommission'] : null,
- ];
- foreach ($data as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMCommissionGoods->updateIsJoin($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- public function test()
- {
- // $obj = new MCommissionCalculate(1,1);
- // try {
- // //$test = $obj->createCommission(8, 891);
- // $test = $obj->upgrade();
- // if (!$test->isSuccess()){
- // parent::sendOutput($test->getData(),$test->getErrorCode());
- // }
- // parent::sendOutput($test->getData());
- // } catch (\Exception $e) {
- // }
- $objMCommissionGoods = new MCommissionGoods(1,1);
- $test = $objMCommissionGoods->formatGoods([
- [
- 'skuId' => '1027',
- 'goodsId' => '130'
- ]
- ]);
- print_r($test);die;
- }
- }
|