Config.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-24
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\system\config;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\system\config\ConfigClassifyRepository;
  13. use app\common\repositories\system\config\ConfigRepository;
  14. use app\validate\admin\ConfigValidate;
  15. use crmeb\services\UploadService;
  16. use FormBuilder\Exception\FormBuilderException;
  17. use think\App;
  18. use think\db\exception\DataNotFoundException;
  19. use think\db\exception\DbException;
  20. use think\db\exception\ModelNotFoundException;
  21. use think\facade\Db;
  22. use think\facade\Log;
  23. /**
  24. * Class Config
  25. * @package app\controller\admin\system\config
  26. * @author xaboy
  27. * @day 2020-03-27
  28. */
  29. class Config extends BaseController
  30. {
  31. /**
  32. * @var ConfigRepository
  33. */
  34. protected $repository;
  35. /**
  36. * Config constructor.
  37. * @param App $app
  38. * @param ConfigRepository $repository
  39. */
  40. public function __construct(App $app, ConfigRepository $repository)
  41. {
  42. parent::__construct($app);
  43. $this->repository = $repository;
  44. }
  45. /**
  46. * @return mixed
  47. * @throws DataNotFoundException
  48. * @throws DbException
  49. * @throws ModelNotFoundException
  50. * @author xaboy
  51. * @day 2020-03-31
  52. */
  53. public function lst()
  54. {
  55. $where = $this->request->params(['keyword']);
  56. [$page, $limit] = $this->getPage();
  57. $lst = $this->repository->lst($where, $page, $limit);
  58. return app('json')->success($lst);
  59. }
  60. /**
  61. * @return mixed
  62. * @throws FormBuilderException
  63. * @author xaboy
  64. * @day 2020-03-31
  65. */
  66. public function createTable()
  67. {
  68. $form = $this->repository->form();
  69. return app('json')->success(formToData($form));
  70. }
  71. /**
  72. * @param int $id
  73. * @return mixed
  74. * @throws DataNotFoundException
  75. * @throws DbException
  76. * @throws ModelNotFoundException
  77. * @throws FormBuilderException
  78. * @author xaboy
  79. * @day 2020-03-31
  80. */
  81. public function updateTable($id)
  82. {
  83. if (!$this->repository->exists($id)) app('json')->fail('数据不存在');
  84. $form = $this->repository->updateForm($id);
  85. return app('json')->success(formToData($form));
  86. }
  87. /**
  88. * @param int $id
  89. * @return mixed
  90. * @throws DbException
  91. * @author xaboy
  92. * @day 2020-03-31
  93. */
  94. public function switchStatus($id)
  95. {
  96. $status = $this->request->param('status', 0);
  97. if (!$this->repository->exists($id))
  98. return app('json')->fail('分类不存在');
  99. $this->repository->switchStatus($id, $status == 1 ? 1 : 0);
  100. return app('json')->success('修改成功');
  101. }
  102. /**
  103. * @param int $id
  104. * @return mixed
  105. * @throws DataNotFoundException
  106. * @throws DbException
  107. * @throws ModelNotFoundException
  108. * @author xaboy
  109. * @day 2020-03-27
  110. */
  111. public function get($id)
  112. {
  113. $data = $this->repository->get($id);
  114. if (!$data)
  115. return app('json')->fail('配置不存在');
  116. else
  117. return app('json')->success($data->hidden(['mer_id', 'value']));
  118. }
  119. /**
  120. * @param ConfigValidate $validate
  121. * @param ConfigClassifyRepository $configClassifyRepository
  122. * @return mixed
  123. * @author xaboy
  124. * @day 2020-03-27
  125. */
  126. public function create(ConfigValidate $validate, ConfigClassifyRepository $configClassifyRepository)
  127. {
  128. $data = $this->request->params(['user_type', 'config_classify_id', 'config_name', 'config_key', 'config_type', 'config_rule', 'required', 'info', 'sort', 'status']);
  129. $validate->check($data);
  130. if (!$configClassifyRepository->exists($data['config_classify_id']))
  131. return app('json')->fail('配置分类不已存在');
  132. if ($this->repository->keyExists($data['config_key']))
  133. return app('json')->fail('配置key已存在');
  134. $this->repository->create($data);
  135. return app('json')->success('添加成功');
  136. }
  137. /**
  138. * @param int $id
  139. * @param ConfigValidate $validate
  140. * @param ConfigClassifyRepository $configClassifyRepository
  141. * @return mixed
  142. * @throws DbException
  143. * @author xaboy
  144. * @day 2020-03-27
  145. */
  146. public function update($id, ConfigValidate $validate, ConfigClassifyRepository $configClassifyRepository)
  147. {
  148. $data = $this->request->params(['user_type', 'config_classify_id', 'config_name', 'config_key', 'config_type', 'config_rule', 'required', 'info', 'sort', 'status']);
  149. $validate->check($data);
  150. if (!$this->repository->exists($id))
  151. return app('json')->fail('分类不存在');
  152. if (!$configClassifyRepository->exists($data['config_classify_id']))
  153. return app('json')->fail('配置分类不已存在');
  154. if ($this->repository->keyExists($data['config_key'], $id))
  155. return app('json')->fail('配置key已存在');
  156. $this->repository->update($id, $data);
  157. return app('json')->success('修改成功');
  158. }
  159. /**
  160. * @param int $id
  161. * @return mixed
  162. * @throws DbException
  163. * @author xaboy
  164. * @day 2020-03-27
  165. */
  166. public function delete($id)
  167. {
  168. $this->repository->delete($id);
  169. return app('json')->success('删除成功');
  170. }
  171. /**
  172. * @param string $key
  173. * @param ConfigClassifyRepository $configClassifyRepository
  174. * @return mixed
  175. * @throws DataNotFoundException
  176. * @throws DbException
  177. * @throws FormBuilderException
  178. * @throws ModelNotFoundException
  179. * @author xaboy
  180. * @day 2020-04-22
  181. */
  182. public function form($key, ConfigClassifyRepository $configClassifyRepository)
  183. {
  184. if (!$configClassifyRepository->keyExists($key) || !($configClassfiy = $configClassifyRepository->keyByData($key)))
  185. return app('json')->fail('配置分类不存在');
  186. $form = $this->repository->cidByFormRule($configClassfiy, $this->request->merId());
  187. return app('json')->success(formToData($form));
  188. }
  189. public function upload($field)
  190. {
  191. $file = $this->request->file($field);
  192. if (!$file)
  193. return app('json')->fail('请上传附件');
  194. $upload = UploadService::create(1);
  195. $data = $upload->to('attach')->validate()->move($field);
  196. if ($data === false) {
  197. return app('json')->fail($upload->getError());
  198. }
  199. $res = $upload->getUploadInfo();
  200. $res['dir'] = path_to_url($res['dir']);;
  201. return app('json')->success(['src' => $res['dir']]);
  202. }
  203. public function iOSExamineStatsu_admin($version,$status)
  204. {
  205. try {
  206. if($status>3||$status<1){
  207. return app('json')->fail('状态值无效');
  208. }
  209. if($status==1){//送审
  210. $insertData=[
  211. 'version'=>$version,
  212. 'status'=>$status,
  213. 'status_time'=>time(),
  214. ];
  215. $res=Db::name('iosexaminestatsu')->insert($insertData);
  216. }elseif($status==2){//结束送审
  217. $updateData=[
  218. 'status'=>$status,
  219. 'overtime'=>time(),
  220. ];
  221. $res= Db::name('iosexaminestatsu')->where(['version'=>$version])->update($updateData);
  222. }
  223. }
  224. catch(\Exception $e){
  225. Log::info('iOS送审状态失败'.$e);
  226. }
  227. if($res){
  228. return app('json')->success('修改成功');
  229. }else{
  230. return app('json')->fail('修改失败');
  231. }
  232. }
  233. }