123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\admin\controller\qa;
- use app\admin\controller\AuthController;
- use app\admin\model\activity\Activity as ActivityModel;
- use app\Request;
- use think\facade\Db;
- use crmeb\services\{
- UtilService as Util, JsonService as Json
- };
- use app\admin\model\qa\QaPost;
- use crmeb\services\JsonService;
- use think\facade\Route as Url;
- use crmeb\services\UtilService;
- use crmeb\services\FormBuilder as Form;
- /**
- * 问答管理
- * Class WechatNews
- * @package app\admin\controller\wechat
- */
- class Questions extends AuthController
- {
- public function index()
- {
- $where = Util::getMore([
- ['title', ''],
- ['status', ''],
- ], $this->request);
- $this->assign('where', $where);
- $this->assign(QaPost::getAll($where));
- return $this->fetch();
- }
- /**
- * 删除图文
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- $res = QaPost::del($id);
- if (!$res)
- return Json::fail('删除失败,请稍候再试!');
- else
- return Json::successful('删除成功!');
- }
- public function fail($id)
- {
- if (!QaPost::be(['id' => $id, 'status' => 0])) return JsonService::fail('操作记录不存在或状态错误!');
- $extract = QaPost::get($id);
- if (!$extract) return JsonService::fail('操作记录不存在!');
- if ($extract->status == 1) return JsonService::fail('已经通过,错误操作');
- if ($extract->status == 2) return JsonService::fail('已被拒绝,请勿重复操作!');
- $res = QaPost::changeFail($id);
- if ($res) {
- return JsonService::successful('操作成功!');
- } else {
- return JsonService::fail('操作失败!');
- }
- }
- public function succ($id)
- {
- if (!QaPost::be(['id' => $id, 'status' => 0]))
- return JsonService::fail('操作记录不存在或状态错误!');
- QaPost::beginTrans();
- $extract = QaPost::get($id);
- if (!$extract) return JsonService::fail('操作记录不存!');
- if ($extract->status == 1) return JsonService::fail('已经通过,错误操作');
- if ($extract->status == 2) return JsonService::fail('已被拒绝,请勿重复操作!');
- $res = QaPost::changeSuccess($id);
- if ($res) {
- QaPost::commitTrans();
- return JsonService::successful('操作成功!');
- } else {
- QaPost::rollbackTrans();
- return JsonService::fail('操作失败!');
- }
- }
- public function create($id = 0)
- {
- $this->assign('id', (int)$id);
- return $this->fetch();
- }
- public function get_questions_info(Request $request, $id = 0)
- {
- $data['questionsInfo'] = [];
- if ($id) {
- $data['questionsInfo'] = QaPost::get($id);
- $data['questionsInfo']['img_list'] = is_string($data['questionsInfo']['img_list']) ? json_decode($data['questionsInfo']['img_list'], true) : [];
- }
- return JsonService::successful($data);
- }
- public function save($id)
- {
- $param = UtilService::postMore([
- 'title',
- 'img_list',
- 'product_title',
- 'product_url',
- 'content'
- ]);
- Db::startTrans();
- try {
- if (count($param['img_list']) < 1) return Json::fail('请上传帖子图片');
- $param['img_list'] = json_encode($param['img_list']);
- if ($id) {
- $param['id'] = $id;
- QaPost::update($param);
- } else {
- $param['add_time'] = time();
- $param['type'] = 1;
- QaPost::create($param);
- }
- Db::commit();
- JsonService::success($id ? '修改帖子成功' : '添加帖子成功');
- } catch (Exception $e) {
- Db::rollback();
- JsonService::fail($e->getMessage());
- }
- }
- }
|