| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- namespace Modules\Manage\Controllers;
- use App\Constants\CommonConstant;
- use App\Repositories\Criterias\FanGroupCriteria;
- use App\Repositories\Criterias\OrderLimitCriteria;
- use App\Repositories\FanGroupRepository;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Modules\Manage\Responses\PaymentSuccessUidResponse;
- class FanGroupController extends BaseController
- {
- public function lists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'page' => 'required|numeric',
- 'page_size' => 'required|numeric',
- 'status' => 'nullable|in:1,2',
- 'title' => 'nullable|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = isset($inputData['page']) ? intval($inputData['page']) : 1;
- $page = format_page($page);
- $orders = [
- ['created_at', 'DESC'],
- ];
- $res = make(FanGroupRepository::class)->pushCriteria(new FanGroupCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return json_success($res);
- }
- /**
- * 创建群组
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function create(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'log' => 'required|string',
- 'title' => 'required|string',
- 'status' => 'required|in:1,2',
- 'link' => 'required|string',
- 'sort' => 'required|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $inserData = [
- 'log' => $inputData['log'],
- 'title' => $inputData['title'],
- 'status' => $inputData['status'],
- 'link' => $inputData['link'],
- 'sort' => $inputData['sort'],
- ];
- $result = make(FanGroupRepository::class)->create($inserData);
- if (!$result) {
- return json_fail('创建失败');
- } else {
- $logSubject = '添加一个支付通道,通道名字:' . $inputData['title'];
- $logSvalue = $result->id;
- $logDbData = [
- 'after_items' => [
- $result->toArray(),
- ],
- 'before_items' => [],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($result->id);
- }
- }
- /**
- * 修改群组
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function modify(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'id' => 'required',
- 'log' => 'nullable|string',
- 'title' => 'nullable|string',
- 'status' => 'nullable|in:1,2',
- 'link' => 'nullable|string',
- 'sort' => 'nullable|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $fanGroupInfo = make(FanGroupRepository::class)->findBy('id', $inputData['id']);
- if (!$fanGroupInfo) {
- return json_fail('修改的粉丝群组不存在!');
- }
- $oldFanGroupInfo = clone $fanGroupInfo;
- if (!empty($inputData['log'])) {
- $fanGroupInfo->log = $inputData['log'];
- }
- if (!empty($inputData['title'])) {
- $fanGroupInfo->title = $inputData['title'];
- }
- if (!empty($inputData['status'])) {
- $fanGroupInfo->status = $inputData['status'];
- }
- if (!empty($inputData['link'])) {
- $fanGroupInfo->link = $inputData['link'];
- }
- if (!empty($inputData['sort'])) {
- $fanGroupInfo->sort = $inputData['sort'];
- }
- $result = $fanGroupInfo->save();
- if (!$result) {
- return json_fail('修改失败');
- } else {
- $logSubject = '修改一个粉丝群组:' . $fanGroupInfo->name;
- $logSvalue = $fanGroupInfo->id;
- $logDbData = [
- 'after_items' => [
- $fanGroupInfo->toArray(),
- ],
- 'before_items' => [
- $oldFanGroupInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($fanGroupInfo->id);
- }
- }
- /**
- * 删除群组
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function delete(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'id' => 'required',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $fanGroupInfo = make(FanGroupRepository::class)->findBy('id', $inputData['id']);
- if (!$fanGroupInfo) {
- return json_fail('删除的粉丝群组不存在!');
- }
- $oldFanGroupInfo = clone $fanGroupInfo;
- $result = $fanGroupInfo->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个粉丝群组:' . $fanGroupInfo->name;
- $logSvalue = $fanGroupInfo->manager_id;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldFanGroupInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($inputData->id);
- }
- }
- }
|