123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\crm\controller;
  3. use app\admin\controller\ApiCommon;
  4. use think\Hook;
  5. use think\Request;
  6. use app\crm\logic\MarketLogic;
  7. class Market extends ApiCommon{
  8. /**
  9. * 用于判断权限
  10. * @permission 无限制
  11. * @allow 登录用户可访问
  12. * @other 其他根据系统设置
  13. **/
  14. public function _initialize()
  15. {
  16. $action = [
  17. 'permission'=>['exceldownload'],
  18. 'allow'=>['index','save','read','update','marketlist']
  19. ];
  20. Hook::listen('check_auth',$action);
  21. $request = Request::instance();
  22. $a = strtolower($request->action());
  23. if (!in_array($a, $action['permission'])) {
  24. parent::_initialize();
  25. }
  26. }
  27. /**
  28. * 市场活动列表
  29. * @author alvin guogaobo
  30. * @version 1.0 版本号
  31. * @since 2021/4/26 0026 17:15
  32. */
  33. public function index(){
  34. $marketLogic=new MarketLogic;
  35. $param=$this->param;
  36. $userInfo = $this->userInfo;
  37. $param['user_id'] = $userInfo['id'];
  38. $data = $marketLogic->getDataList($param);
  39. return resultArray(['data' => $data]);
  40. }
  41. /**
  42. * 关联对象列表
  43. * @author alvin guogaobo
  44. * @version 1.0 版本号
  45. * @since 2021/4/26 0026 17:14
  46. */
  47. public function marketList(){
  48. $marketLogic=new MarketLogic;
  49. $data = $marketLogic->marketList();
  50. return resultArray(['data' => $data]);
  51. }
  52. public function save(){
  53. $marketLogic=new MarketLogic;
  54. $param = $this->param;
  55. $userInfo = $this->userInfo;
  56. $param['create_user_id'] = $userInfo['id'];
  57. # 检查活动图片
  58. if (!empty($param['cover_images']) && count(explode(',', $param['cover_images'])) > 9) {
  59. return resultArray(['error' => '最多只能上次9张产品图片!']);
  60. }
  61. # 检查活动详情图片
  62. if (!empty($param['details_images']) && count(explode(',', $param['details_images'])) > 9) {
  63. return resultArray(['error' => '最多只能上次9张产品详情图片!']);
  64. }
  65. if ($marketLogic->createData($param)) {
  66. return resultArray(['data' => '添加成功']);
  67. } else {
  68. return resultArray(['error' => '添加失败']);
  69. }
  70. }
  71. public function update(){
  72. $marketLogic=new MarketLogic;
  73. $param = $this->param;
  74. $userInfo = $this->userInfo;
  75. $param['user_id'] = $userInfo['id'];
  76. # 检查产品图片
  77. if (!empty($param['cover_images']) && count(explode(',', $param['cover_images'])) > 9) {
  78. return resultArray(['error' => '最多只能上次9张产品图片!']);
  79. }
  80. # 检查产品详情图片
  81. if (!empty($param['details_images']) && count(explode(',', $param['details_images'])) > 9) {
  82. return resultArray(['error' => '最多只能上次9张产品详情图片!']);
  83. }
  84. if ($marketLogic->updateDataById($param, $param['id'])) {
  85. return resultArray(['data' => '编辑成功']);
  86. } else {
  87. return resultArray(['error' => '编辑失败']);
  88. }
  89. }
  90. public function read()
  91. {
  92. $marketLogic=new MarketLogic;
  93. $userModel = new \app\admin\model\User();
  94. $param = $this->param;
  95. $userInfo = $this->userInfo;
  96. $data = $marketLogic->getDataById($param['id'], $userInfo['id']);
  97. //判断权限
  98. $auth_user_ids = $userModel->getUserByPer('crm', 'Market', 'read');
  99. if (!in_array($data['owner_user_id'], $auth_user_ids)) {
  100. //无权限
  101. $authData['dataAuth'] = (int)0;
  102. return resultArray(['data' => $authData]);
  103. }
  104. if (!$data) {
  105. return resultArray(['error' => $marketLogic->getError()]);
  106. }
  107. return resultArray(['data' => $data]);
  108. }
  109. public function delete(){
  110. $marketLogic=new MarketLogic;
  111. $userInfo = $this->userInfo;
  112. $id_list = (array) $this->param['id'];
  113. $id_list['user_id']=$userInfo['id'];
  114. $id_list = array_map('intval', $id_list);
  115. $data=$marketLogic->delete($id_list);
  116. if($data){
  117. return resultArray(['data' => '删除成功']);
  118. }else{
  119. return resultArray(['error' => '删除失败']);
  120. }
  121. }
  122. public function enables(){
  123. $marketModel = model('Market');
  124. $param = $this->param;
  125. $userInfo=$this->userInfo;
  126. $id = [$param['flow_id']];
  127. $data = $marketModel->enableDatas($id, $param['status']);
  128. # 系统操作日志
  129. if (!$data) {
  130. return resultArray(['error' => $marketModel->getError()]);
  131. }
  132. if($param['status']==0){
  133. $content='禁用了:';
  134. }else{
  135. $content='启用了:';
  136. }
  137. $dataInfo=db('admin_examine_flow')->where('flow_id',$param['flow_id'])->find();
  138. SystemActionLog($userInfo['id'], 'admin_examine','approval', $param['flow_id'], 'update', $dataInfo['name'], '', '',$content.$dataInfo['name']);
  139. return resultArray(['data' => '操作成功']);
  140. }
  141. }