123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- <?php
- /**
- * 积分商品管理Model
- * Created by PhpStorm.
- * User: haoren
- * Date: 2021/03/25
- * Time: 16:00
- */
- namespace JinDouYun\Model\Integral;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Integral\DIntegralGoods;
- use JinDouYun\Dao\Integral\DIntegralGoodsExchange;
- use JinDouYun\Dao\Integral\DIntegralRule;
- use JinDouYun\Dao\Customer\DCustomerIntegralDesc;
- use JinDouYun\Dao\UserCenter\DUserCenter;
- use JinDouYun\Model\MBaseModel;
- use JinDouYun\Model\Customer\MCustomer;
- class MIntegralGoods extends MBaseModel
- {
- private $objDIntegralGoods;
- private $objDIntegralGoodsExchange;
- private $objDIntegralRule;
- private $userCenterId;
- private $enterpriseId;
- public function __construct($enterpriseId, $userCenterId = false)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- $this->objDIntegralGoods = new DIntegralGoods('default');
- $this->objDIntegralGoodsExchange = new DIntegralGoodsExchange('default');
- $this->objDIntegralRule = new DIntegralRule('default');
- $this->objDIntegralGoods->setTable('qianniao_integral_goods_' . $enterpriseId);
- $this->objDIntegralGoodsExchange->setTable('qianniao_integral_goods_exchange_' . $enterpriseId);
- $this->objDIntegralRule->setTable('qianniao_integral_rule_' . $enterpriseId);
- }
- /**
- * 积分商品添加
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addIntegralGoods($params)
- {
- $params['deleteStatus'] = StatusCode::$standard;
- $params['enableStatus'] = StatusCode::$standard;
- $params['createTime'] = time();
- $params['updateTime'] = time();
- $dbResult = $this->objDIntegralGoods->insert($params);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 积分商品删除
- * @param $where
- * @return ResultWrapper
- */
- public function deleteIntegralGoods($where)
- {
- $params = [
- 'deleteStatus' => StatusCode::$delete,
- 'updateTime' => time(),
- ];
- $dbResult = $this->objDIntegralGoods->update($params, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $returnData = $dbResult;
- return ResultWrapper::success($returnData);
- }
- /**
- * 积分商品禁用
- * @param $where
- * @return ResultWrapper
- */
- public function enableIntegralGoods($where)
- {
- $dbResult = $this->objDIntegralGoods->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $update = [
- 'enableStatus' => StatusCode::$standard,
- 'updateTime' => time(),
- ];
- if($dbResult['enableStatus'] == StatusCode::$standard){
- $update['enableStatus'] = StatusCode::$delete;
- }
- $dbResult = $this->objDIntegralGoods->update($update, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $returnData = $dbResult;
- return ResultWrapper::success($returnData);
- }
- /**
- * 积分商品修改
- * @param $updateData
- * @param $where
- * @return ResultWrapper
- */
- public function updateIntegralGoods($updateData, $where)
- {
- $dbResult = $this->objDIntegralGoods->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$paramError);
- }
- $goods = $dbResult;
- unset($dbResult);
- $dbResult = $this->objDIntegralGoods->update($updateData, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 积分商品列表
- * @param $selectParams
- * @return ResultWrapper
- * @throws Exception
- */
- public function getAllIntegralGoods($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $selectParams['deleteStatus'] = StatusCode::$standard;
- isset($selectParams['search']) && $selectParams['search'] = ['name' => $selectParams['search']];
- $selectParams = self::formatSqlWhere($selectParams);
- $dbResult = $this->objDIntegralGoods->select($selectParams,'*', 'sort desc,createTime desc', $limit, $offset);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $countResult = $this->objDIntegralGoods->count($selectParams);
- if ($countResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $return = [
- 'data' => self::formatIntegralGoods($dbResult),
- 'total' => ($countResult) ? intval($countResult) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 积分商品详情
- * @param $where
- * @return ResultWrapper
- * @throws Exception
- */
- public function getIntegralGoodsInfo($where)
- {
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralGoods->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success(self::formatIntegralGoods($dbResult));
- }
- /**
- * 积分商品格式化
- * @param $params
- * @return array
- */
- public function formatIntegralGoods($params)
- {
- if(isset($params['id'])){
- $data = [$params];
- }else{
- $data = $params;
- }
- foreach($data as &$value){
- $value['images'] = json_decode($value['images'], true);
- $value['categoryName'] = $value['category'] == StatusCode::$delete ? '虚拟商品' : '实物商品';
- $value['details'] = htmlspecialchars_decode($value['details'], ENT_QUOTES);
- }
- unset($value);
- if(isset($params['id'])){
- $return = array_shift($data);
- }else{
- $return = $data;
- }
- return $return;
- }
- /**
- * 查询积分商品数据
- * @param $where
- * @return ResultWrapper
- */
- public function getIntegralGoods($where)
- {
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralGoods->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 查询积分商品数据
- * @param $where
- * @return ResultWrapper
- */
- public function selectIntegralGoods($where)
- {
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralGoods->select($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 积分商品兑换添加
- * @param $params
- * @return ResultWrapper
- */
- public function addIntegralGoodsExchange($params)
- {
- //查询商品
- $dbResult = $this->objDIntegralGoods->get(['id' => $params['goodsId'], 'deleteStatus' => StatusCode::$standard]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $goods = $dbResult;
- unset($dbResult);
- if(empty($goods)){
- return ResultWrapper::fail('商品不存在', ErrorCode::$paramError);
- }
- if($goods['enableStatus'] == StatusCode::$delete){
- return ResultWrapper::fail('商品已下架', ErrorCode::$paramError);
- }
- /* if($params['num'] > $goods['num']){
- return ResultWrapper::fail('商品可兑换数量不足', ErrorCode::$paramError);
- }*/
- if($params['num'] > $goods['limit']){
- return ResultWrapper::fail('每位用户限购'.$goods['limit'], ErrorCode::$paramError);
- }
- $params['integral'] = $goods['integral'];
- $params['amount'] = bcmul($params['num'], $params['integral'], 2);
- //查询客户
- $objMCustomer = new MCustomer($this->enterpriseId, $this->userCenterId);
- $where = [
- 'userCenterId' => isset($params['userCenterId']) ? $params['userCenterId'] : $this->userCenterId,
- 'deleteStatus' => StatusCode::$standard
- ];
- $modelResult = $objMCustomer->getCustomerData($where);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $customer = $modelResult->getData();
- unset($modelResult);
- if(empty($customer)){
- return ResultWrapper::fail('用户不存在', ErrorCode::$paramError);
- }
- $whereGoodsExchange = [
- 'customerId' => $customer['id'],
- 'goodsId' => $goods['id'],
- 'shopId' => $params['shopId'],
- 'status' => [4,5]
- ];
- $sql = 'select sum(num) as num from qianniao_integral_goods_exchange_'.$this->enterpriseId.' where '.self::formatSqlWhere($whereGoodsExchange);
- $dbResult = $this->objDIntegralGoodsExchange->query($sql);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- $exchangeNum = $dbResult[0]['num'];
- unset($dbResult);
- if(bcadd($exchangeNum, $params['num']) > $goods['limit']){
- return ResultWrapper::fail('每位用户限购'.$goods['limit'], ErrorCode::$paramError);
- }
- if($customer['integral'] < $params['amount']){
- return ResultWrapper::fail('积分不足', ErrorCode::$paramError);
- }
- $beginStatus = $this->objDIntegralGoodsExchange->beginTransaction();
- //扣除积分
- $updateCustomer = [
- 'integral' => bcsub($customer['integral'], $params['amount'], 2),
- 'updateTime' => time()
- ];
- $modelResult = $objMCustomer->updateCustomer($updateCustomer, ['id' => $customer['id']]);
- if(!$modelResult->isSuccess()){
- $this->objDIntegralGoodsExchange->rollBack();
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- unset($modelResult);
- $params['status'] = StatusCode::$delete;
- $params['no'] = createOrderSn(StatusCode::$source['manage'], 99, $params['userCenterId']);
- $params['createTime'] = time();
- $params['updateTime'] = time();
- $params['customerId'] = $customer['id'];
- $dbResult = $this->objDIntegralGoodsExchange->insert($params);
- if($dbResult === false){
- $this->objDIntegralGoodsExchange->rollBack();
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- $exchangeId = $dbResult;
- unset($dbResult);
- //增加记录
- $insertIntegralDesc = [
- 'userCenterId' => $customer['userCenterId'],
- 'customerId' => $customer['id'],
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : 0,
- 'originId' => $exchangeId,
- 'originNo' => $params['no'],
- 'title' => '积分兑换商品',
- 'amount' => $params['amount'],
- 'changeAmount' => $updateCustomer['integral'],
- 'type' => StatusCode::$delete,
- 'source' => 4,
- 'createTime' => time(),
- 'updateTime' => time(),
- ];
- $objDCustomerIntegralDesc = new DCustomerIntegralDesc();
- $objDCustomerIntegralDesc->set_Table('qianniao_customer_integral_desc_'.$this->enterpriseId);
- $dbResult = $objDCustomerIntegralDesc->insert($insertIntegralDesc);
- if($dbResult === false){
- $this->objDIntegralGoodsExchange->rollBack();
- return ResultWrapper::fail($objDCustomerIntegralDesc->error(), ErrorCode::$dberror);
- }
- //修改商品
- $updateGoods = [
- 'num' => bcsub($goods['num'], $params['num']),
- 'changeNum' => bcadd($goods['changeNum'], $params['num']),
- 'updateTime' => time()
- ];
- $dbResult = $this->objDIntegralGoods->update($updateGoods, ['id' => $goods['id']]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoods->error(), ErrorCode::$dberror);
- }
- $beginStatus && $this->objDIntegralGoodsExchange->commit();
- return ResultWrapper::success($exchangeId);
- }
- /**
- * 积分商品兑换修改
- * @param $update
- * @param $where
- * @return ResultWrapper
- */
- public function updateIntegralGoodsExchange($update, $where)
- {
- $dbResult = $this->objDIntegralGoodsExchange->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- $exchange = $dbResult;
- unset($dbResult);
- if(isset($update['status']) && $update['status'] == 6 && $exchange['status'] != 4){
- return ResultWrapper::fail('订单已完成', ErrorCode::$paramError);
- }
- if(isset($update['status']) && $update['status'] == 5 && $exchange['status'] != 4){
- return ResultWrapper::fail('订单已失效', ErrorCode::$paramError);
- }
- if($update['status'] == 6){
- //返还积分
- $objMCustomer = new MCustomer($this->enterpriseId, $this->userCenterId);
- $modelResult = $objMCustomer->getCustomerData(['id' => $exchange['customerId']]);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- $customer = $modelResult->getData();
- unset($modelResult);
- $updateCustomer = [
- 'integral' => bcadd($customer['integral'], $exchange['amount'], 2),
- 'updateTime' => time(),
- ];
- $modelResult = $objMCustomer->updateCustomer($updateCustomer, ['id' => $customer['id']]);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
- }
- //增加记录
- $insertIntegralDesc = [
- 'userCenterId' => $customer['userCenterId'],
- 'customerId' => $customer['id'],
- 'shopId' => isset($exchange['shopId']) ? $exchange['shopId'] : 0,
- 'originId' => $exchange['id'],
- 'originNo' => $exchange['no'],
- 'title' => '积分兑换商品失效,返还积分',
- 'amount' => $exchange['amount'],
- 'changeAmount' => $updateCustomer['integral'],
- 'type' => StatusCode::$standard,
- 'source' => 5,
- 'createTime' => time(),
- 'updateTime' => time(),
- ];
- $objDCustomerIntegralDesc = new DCustomerIntegralDesc();
- $objDCustomerIntegralDesc->set_Table('qianniao_customer_integral_desc_'.$this->enterpriseId);
- $dbResult = $objDCustomerIntegralDesc->insert($insertIntegralDesc);
- if($dbResult === false){
- return ResultWrapper::fail($objDCustomerIntegralDesc->error(), ErrorCode::$dberror);
- }
- }
- $update['updateTime'] = time();
- $dbResult = $this->objDIntegralGoodsExchange->update($update,$where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 积分商品兑换列表
- * @return ResultWrapper
- */
- public function getAllIntegralGoodsExchange($params)
- {
- $sql = 'select e.*,g.name as integralGoodsName,g.category,g.images,c.name as customerName from qianniao_integral_goods_exchange_'.$this->enterpriseId.' e left join qianniao_integral_goods_'.$this->enterpriseId.' g on g.id = e.goodsId left join qianniao_customer_'.$this->enterpriseId.' c on c.id = e.customerId';
- $whereSql = '';
- if(isset($params['shopId'])){
- $whereSql .= (!empty($whereSql) ? ' and ' : '').' e.shopId = '.$params['shopId'];
- }
- if(isset($params['userCenterId'])){
- $whereSql .= (!empty($whereSql) ? ' and ' : '').' e.userCenterId = '.$params['userCenterId'];
- }
- if(isset($params['search'])){
- $whereSql .= (!empty($whereSql) ? ' and ' : '').' (c.name like "%'.$params['search'].'%" or g.name like "%'.$params['search'].'%")';
- }
- if(isset($params['status'])){
- $whereSql .= (!empty($whereSql) ? ' and ' : '').' e.status = '.$params['status'];
- }
- !empty($whereSql) && $whereSql = ' where '.$whereSql;
- $orderSql = ' order by e.createTime desc';
- $dbResult = $this->objDIntegralGoodsExchange->query($sql.$whereSql.$orderSql);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- $data = $dbResult;
- unset($dbResult);
- $countSql = 'select count(*) as count from qianniao_integral_goods_exchange_'.$this->enterpriseId.' e left join qianniao_integral_goods_'.$this->enterpriseId.' g on g.id = e.goodsId left join qianniao_customer_'.$this->enterpriseId.' c on c.id = e.customerId';
- $dbResult = $this->objDIntegralGoodsExchange->query($countSql.$whereSql);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- $count = $dbResult;
- unset($dbResult);
- $return = [
- 'data' => self::formatIntegralGoodsExchange($data),
- 'total' => isset($count[0]['count']) ? $count[0]['count'] : 0
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 积分商品兑换详情
- * @param $where
- * @return ResultWrapper
- */
- public function getIntegralGoodsExchangeInfo($params)
- {
- $sql = 'select e.*,g.name as integralGoodsName,g.category,g.images,c.name as customerName from qianniao_integral_goods_exchange_'.$this->enterpriseId.' e left join qianniao_integral_goods_'.$this->enterpriseId.' g on g.id = e.goodsId left join qianniao_customer_'.$this->enterpriseId.' c on c.id = e.customerId';
- $whereSql = '';
- if(isset($params['id'])){
- $whereSql .= (!empty($whereSql) ? ' and ' : '').' e.id = '.$params['id'];
- }
- !empty($whereSql) && $whereSql = ' where '.$whereSql;
- $limitSql = ' limit 1';
- $dbResult = $this->objDIntegralGoodsExchange->query($sql.$whereSql.$limitSql);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralGoodsExchange->error(), ErrorCode::$dberror);
- }
- $data = array_shift($dbResult);
- unset($dbResult);
- return ResultWrapper::success(self::formatIntegralGoodsExchange($data));
- }
- /**
- * 积分商品兑换格式化
- * @param $params
- * @return array|mixed
- */
- public function formatIntegralGoodsExchange($params)
- {
- if(isset($params['id'])){
- $data = [$params];
- }else{
- $data = $params;
- }
- $userCenterIds = array_column($data, 'userCenterId');
- $userCenterData = [];
- if(!empty($userCenterIds)){
- $objDUserCenter = new DUserCenter();
- $dbResult = $objDUserCenter->select(['id' => $userCenterIds]);
- if($dbResult){
- foreach($dbResult as $value){
- $userCenterData[$value['id']] = $value['mobile'];
- }
- }
- unset($dbResult);
- }
- foreach($data as &$value){
- $value['images'] = !empty($value['images']) ? json_decode($value['images'], true) : [];
- $value['categoryName'] = $value['category'] == StatusCode::$delete ? '虚拟商品' : '实物商品';
- $value['address'] = !empty($value['address']) ? json_decode($value['address'], true) : [];
- $value['mobile'] = isset($userCenterData[$value['userCenterId']]) ? $userCenterData[$value['userCenterId']] : '';
- }
- unset($value);
- if(isset($params['id'])){
- $return = array_shift($data);
- }else{
- $return = $data;
- }
- return $return;
- }
- /**
- * 积分规则添加
- * @param $params
- * @return ResultWrapper
- */
- public function addIntegralRule($params)
- {
- $dbResult = $this->objDIntegralRule->update(['enableStatus' => StatusCode::$delete, 'updateTime' => time()]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- $params['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralRule->insert($params);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 积分规则删除
- * @param $where
- * @return ResultWrapper
- */
- public function deleteIntegralRule($where)
- {
- $params = [
- 'deleteStatus' => StatusCode::$delete,
- 'updateTime' => time(),
- ];
- $dbResult = $this->objDIntegralRule->update($params, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- $returnData = $dbResult;
- return ResultWrapper::success($returnData);
- }
- /**
- * 积分规则禁用
- * @param $where
- * @return ResultWrapper
- */
- public function enableIntegralRule($where)
- {
- $dbResult = $this->objDIntegralRule->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- $update = [
- 'enableStatus' => StatusCode::$standard,
- 'updateTime' => time(),
- ];
- if($dbResult['enableStatus'] == StatusCode::$standard){
- $update['enableStatus'] = StatusCode::$delete;
- }else{
- $result = $this->objDIntegralRule->update(['enableStatus' => StatusCode::$delete, 'updateTime' => time()],['enableStatus' => StatusCode::$standard]);
- if ($result === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- }
- $dbResult = $this->objDIntegralRule->update($update, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- $returnData = $dbResult;
- return ResultWrapper::success($returnData);
- }
- /**
- * 积分规则修改
- * @param $updateData
- * @param $where
- * @return ResultWrapper
- */
- public function updateIntegralRule($updateData, $where)
- {
- $dbResult = $this->objDIntegralRule->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$paramError);
- }
- $rule = $dbResult;
- unset($dbResult);
- $dbResult = $this->objDIntegralRule->update($updateData, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 积分规则列表
- * @param $selectParams
- * @return ResultWrapper
- * @throws Exception
- */
- public function getAllIntegralRule($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $selectParams['deleteStatus'] = StatusCode::$standard;
- isset($selectParams['search']) && $selectParams['search'] = ['title' => $selectParams['search']];
- $selectParams = self::formatSqlWhere($selectParams);
- $dbResult = $this->objDIntegralRule->select($selectParams,'*', 'createTime desc', $limit, $offset);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- $countResult = $this->objDIntegralRule->count($selectParams);
- if ($countResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- $return = [
- 'data' => self::formatIntegralRule($dbResult),
- 'total' => ($countResult) ? intval($countResult) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 积分规则详情
- * @param $where
- * @return ResultWrapper
- * @throws Exception
- */
- public function getIntegralRuleInfo($where)
- {
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralRule->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success(self::formatIntegralRule($dbResult));
- }
- /**
- * 积分规则格式化
- * @param $params
- * @return array
- */
- public function formatIntegralRule($params)
- {
- if(isset($params['id'])){
- $data = [$params];
- }else{
- $data = $params;
- }
- foreach($data as &$value){
- $value['goods'] = json_decode($value['goods'], true);
- }
- unset($value);
- if(isset($params['id'])){
- $return = array_shift($data);
- }else{
- $return = $data;
- }
- return $return;
- }
- /**
- * 查询积分规则数据
- * @param $where
- * @return ResultWrapper
- */
- public function getIntegralRule($where)
- {
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralRule->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 查询积分规则数据
- * @param $where
- * @return ResultWrapper
- */
- public function selectIntegralRule($where)
- {
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDIntegralRule->select($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDIntegralRule->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- }
|