MShopCardBind.Class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Model\Shop;
  10. use Exception;
  11. use JinDouYun\Dao\Shop\DShopCardBind;
  12. use JinDouYun\Dao\Shop\DShopProject;
  13. use Mall\Framework\Core\ErrorCode;
  14. use Mall\Framework\Core\StatusCode;
  15. use Mall\Framework\Core\ResultWrapper;
  16. use JinDouYun\Model\MBaseModel;
  17. use Monolog\Handler\IFTTTHandler;
  18. class MShopCardBind extends MBaseModel
  19. {
  20. private $obj;
  21. private $cutTable = 250000;
  22. private $enterpriseId;
  23. private $userCenterId;
  24. private $DProject;
  25. public function __construct($enterpriseId, $userCenterId = '')
  26. {
  27. $this->enterpriseId = $enterpriseId;
  28. $this->userCenterId = $userCenterId;
  29. parent::__construct($this->enterpriseId, $this->userCenterId);
  30. $this->obj = new DShopCardBind('default');
  31. $this->DProject = new DShopProject('default');
  32. }
  33. /**
  34. * 列表
  35. * @param $where
  36. * @return mixed
  37. */
  38. public function list($where)
  39. {
  40. $limit = isset($where['limit']) ? $where['limit'] : 0;
  41. unset($where['limit']);
  42. $offset = isset($where['offset']) ? $where['offset'] : 0;
  43. unset($where['offset']);
  44. $dbResult = $this->obj->select($where, '*', 'id DESC', $limit, $offset);
  45. $count = $this->obj->count($where);
  46. if ($dbResult === false) {
  47. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  48. }
  49. foreach ($dbResult as &$item)
  50. {
  51. $project = $this->DProject->get(['id' => $item['project_id']]);
  52. $item['project_name'] = $project['name'];
  53. }
  54. $return = [
  55. 'data' => $dbResult,
  56. 'total' => $count,
  57. ];
  58. if($return === false){
  59. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  60. }else{
  61. return ResultWrapper::success($return);
  62. }
  63. }
  64. /**
  65. * 详情
  66. * @param $where
  67. * @return mixed
  68. */
  69. public function details($where)
  70. {
  71. if(empty($where)){
  72. return ResultWrapper::success($where);
  73. }
  74. $dbResult = $this->obj->get($where);
  75. if($dbResult === false){
  76. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  77. }
  78. return ResultWrapper::success(self::formatInfo($dbResult));
  79. }
  80. /**
  81. * Doc: (des="添加")
  82. * User: XMing
  83. * Date: 2020/7/15
  84. * Time: 10:42 上午
  85. * @throws Exception
  86. * @param array $params
  87. * @return ResultWrapper
  88. */
  89. public function insert(array $params)
  90. {
  91. $res = $this->obj->insert($params);
  92. if ($res){
  93. return ResultWrapper::success('添加成功');
  94. }else{
  95. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  96. }
  97. }
  98. public function update($params, $id)
  99. {
  100. $data = $this->obj->get($id);
  101. if (!$data){
  102. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  103. }
  104. $dbResult = $this->obj->update($params,$id);
  105. if($dbResult === false){
  106. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  107. }
  108. return ResultWrapper::success('修改成功');
  109. }
  110. /**
  111. * 格式数据详情
  112. * @param $data
  113. * @return mixed
  114. */
  115. public function formatInfo($data)
  116. {
  117. return $data;
  118. }
  119. public function delete($where)
  120. {
  121. $res = $this->obj->delete($where);
  122. if ($res){
  123. return ResultWrapper::success('删除成功');
  124. }
  125. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  126. }
  127. }