123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- /**
- * 商铺管理模块
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/10/31
- * Time: 15:02
- */
- namespace JinDouYun\Model\Shop;
- use Exception;
- use JinDouYun\Dao\Shop\DShopCardBind;
- use JinDouYun\Dao\Shop\DShopProject;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Model\MBaseModel;
- use Monolog\Handler\IFTTTHandler;
- class MShopCardBind extends MBaseModel
- {
- private $obj;
- private $cutTable = 250000;
- private $enterpriseId;
- private $userCenterId;
- private $DProject;
- public function __construct($enterpriseId, $userCenterId = '')
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- parent::__construct($this->enterpriseId, $this->userCenterId);
- $this->obj = new DShopCardBind('default');
- $this->DProject = new DShopProject('default');
- }
- /**
- * 列表
- * @param $where
- * @return mixed
- */
- public function list($where)
- {
- $limit = isset($where['limit']) ? $where['limit'] : 0;
- unset($where['limit']);
- $offset = isset($where['offset']) ? $where['offset'] : 0;
- unset($where['offset']);
- $dbResult = $this->obj->select($where, '*', 'id DESC', $limit, $offset);
- $count = $this->obj->count($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- foreach ($dbResult as &$item)
- {
- $project = $this->DProject->get(['id' => $item['project_id']]);
- $item['project_name'] = $project['name'];
- }
- $return = [
- 'data' => $dbResult,
- 'total' => $count,
- ];
- if($return === false){
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($return);
- }
- }
- /**
- * 详情
- * @param $where
- * @return mixed
- */
- public function details($where)
- {
- if(empty($where)){
- return ResultWrapper::success($where);
- }
- $dbResult = $this->obj->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success(self::formatInfo($dbResult));
- }
- /**
- * Doc: (des="添加")
- * User: XMing
- * Date: 2020/7/15
- * Time: 10:42 上午
- * @throws Exception
- * @param array $params
- * @return ResultWrapper
- */
- public function insert(array $params)
- {
- $res = $this->obj->insert($params);
- if ($res){
- return ResultWrapper::success('添加成功');
- }else{
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- }
- public function update($params, $id)
- {
- $data = $this->obj->get($id);
- if (!$data){
- return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
- }
- $dbResult = $this->obj->update($params,$id);
- if($dbResult === false){
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success('修改成功');
- }
- /**
- * 格式数据详情
- * @param $data
- * @return mixed
- */
- public function formatInfo($data)
- {
- return $data;
- }
- public function delete($where)
- {
- $res = $this->obj->delete($where);
- if ($res){
- return ResultWrapper::success('删除成功');
- }
- return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
- }
- }
|