MArticle.Class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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\Enterprise;
  10. use Exception;
  11. use JinDouYun\Dao\Enterprise\DArticle;
  12. use JinDouYun\Dao\Enterprise\DPersonnel;
  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 MArticle extends MBaseModel
  19. {
  20. private $obj;
  21. private $cutTable = 250000;
  22. private $enterpriseId;
  23. private $userCenterId;
  24. private $objMShopPartner;
  25. private $objMStaff;
  26. public function __construct($enterpriseId, $userCenterId = '')
  27. {
  28. $this->enterpriseId = $enterpriseId;
  29. $this->userCenterId = $userCenterId;
  30. parent::__construct($this->enterpriseId, $this->userCenterId);
  31. $this->obj = new DArticle('default');
  32. }
  33. /**
  34. * 列表
  35. * @param $where
  36. * @return mixed
  37. */
  38. public function list($where)
  39. {
  40. $limit = $where['limit'];
  41. unset($where['limit']);
  42. $offset = $where['offset'];
  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. $return = [
  50. 'data' => $dbResult,
  51. 'total' => $count,
  52. ];
  53. if($return === false){
  54. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  55. }else{
  56. return ResultWrapper::success($return);
  57. }
  58. }
  59. /**
  60. * 详情
  61. * @param $where
  62. * @return mixed
  63. */
  64. public function details($where)
  65. {
  66. if(empty($where)){
  67. return ResultWrapper::success($where);
  68. }
  69. $dbResult = $this->obj->get($where);
  70. $dbResult['content'] = html_entity_decode($dbResult['content']);
  71. if($dbResult === false){
  72. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  73. }
  74. return ResultWrapper::success(self::formatInfo($dbResult));
  75. }
  76. /**
  77. * Doc: (des="添加")
  78. * User: XMing
  79. * Date: 2020/7/15
  80. * Time: 10:42 上午
  81. * @throws Exception
  82. * @param array $params
  83. * @return ResultWrapper
  84. */
  85. public function insert(array $params)
  86. {
  87. $res = $this->obj->insert($params);
  88. if ($res){
  89. return ResultWrapper::success('添加成功');
  90. }else{
  91. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  92. }
  93. }
  94. public function update($params, $id)
  95. {
  96. $data = $this->obj->get($id);
  97. if (!$data){
  98. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  99. }
  100. $dbResult = $this->obj->update($params,$id);
  101. if($dbResult === false){
  102. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  103. }
  104. return ResultWrapper::success('修改成功');
  105. }
  106. /**
  107. * 格式数据详情
  108. * @param $data
  109. * @return mixed
  110. */
  111. public function formatInfo($data)
  112. {
  113. return $data;
  114. }
  115. public function delete($where)
  116. {
  117. $res = $this->obj->delete($where);
  118. if ($res){
  119. return ResultWrapper::success('删除成功');
  120. }
  121. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  122. }
  123. }