Pay.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/16 23:06
  5. */
  6. namespace app\api\controller;
  7. use app\api\BaseController;
  8. use app\api\exception\ApiException;
  9. use app\api\model\AdminModel;
  10. use app\api\model\BrandModel;
  11. use app\api\model\CompanyModel;
  12. use app\api\model\GroupModel;
  13. use app\api\model\PayModel;
  14. use app\common\until\Until;
  15. class Pay extends BaseController {
  16. /**
  17. * @OA\Get(path="/api/Pay/index",
  18. * tags={"支付管理"},
  19. * summary="支付配置列表",
  20. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  21. * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
  22. * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
  23. * @OA\Parameter(name="status", in="query", description="状态 1正常 2删除", @OA\Schema(type="integer",default="1")),
  24. * @OA\Parameter(name="code", in="query", description="支付code", @OA\Schema(type="string")),
  25. * @OA\Parameter(name="groupId", in="query", description="公司id", @OA\Schema(type="integer")),
  26. * @OA\RequestBody(
  27. * ),
  28. * @OA\Response(response="200", description="请求成功")
  29. * )
  30. */
  31. public function index() {
  32. $input = Until::getInput();
  33. $model = new PayModel();
  34. $model->setPage($input['page'] ?? 1);
  35. $model->setPageSize($input['pageSize'] ?? 10);
  36. if ($this->isAdmin()) {
  37. $where = [];
  38. } else {
  39. $where[] = ['status', '=', $model::NORMAL];
  40. }
  41. if (!empty($input['code'])) {
  42. $where[] = ['pay_code', 'like', "%{$input['code']}%"];
  43. }
  44. if (!empty($input['groupId'])) {
  45. $where[] = ['group_id', '=', "{$input['groupId']}"];
  46. }
  47. // $where[] = ['gr.admin_id','=',$this->adminId];
  48. $model->setWhere($where);
  49. $data = $model->getPageList($model);
  50. Until::output($data);
  51. }
  52. /**
  53. * @OA\Post(path="/api/Pay/save",
  54. * tags={"支付管理"},
  55. * summary="保存支付配置信息",
  56. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  57. * @OA\RequestBody(
  58. * @OA\MediaType(
  59. * mediaType="multipart/form-data",
  60. * @OA\Schema(
  61. * @OA\Property(description="支付code", property="code", type="string", default="jj公司"),
  62. * @OA\Property(description="状态 1正常 2删除", property="status", type="integer", default="1"),
  63. * @OA\Property(description="备注", property="remark", type="string", default="xx支付"),
  64. * @OA\Property(description="集团id", property="groupId", type="string", default="xx支付"),
  65. * required={"code"})
  66. * )
  67. * ),
  68. * @OA\Response(response="200", description="请求成功")
  69. * )
  70. */
  71. public function save() {
  72. $input = Until::getInput();
  73. $rule = [
  74. 'code|支付code' => 'require',
  75. // 'masterPayId|主商户号' => 'require',
  76. //'subPayId|子商户号' => 'require',
  77. // 'masterAppId|主appId' => 'require',
  78. //'subAppId|子appId' => 'require',
  79. 'groupId|集团id' => 'require',
  80. // 'xcxSecret|秘钥' => 'require',
  81. ];
  82. Until::check($rule, $input);
  83. $model = new PayModel();
  84. if (!empty($input['id'])) {
  85. $id = (int)$input['id'];
  86. $model::where(['id' => $id])->update([
  87. 'pay_code' => $input['code'],
  88. // 'master_pay_id' => $input['masterPayId'],
  89. // 'sub_pay_id' => $input['subPayId'],
  90. // 'master_app_id' => $input['masterAppId'],
  91. // 'sub_app_id' => $input['subAppId'],
  92. // 'xcx_secret' => $input['xcxSecret'],
  93. 'group_id' => $input['groupId'],
  94. 'status' => $input['status'] ?? 1,
  95. 'remark' => $input['remark']
  96. ]);
  97. } else {
  98. $rs = $model::where(['pay_code' => $input['code']])->find();
  99. if (!empty($rs)) {
  100. throw new ApiException('存在相同payCode');
  101. }
  102. $id = $model->insertGetId([
  103. 'pay_code' => $input['code'],
  104. // 'master_pay_id' => $input['masterPayId'],
  105. // 'sub_pay_id' => $input['subPayId'] ?? "",
  106. // 'master_app_id' => $input['masterAppId'],
  107. // 'sub_app_id' => $input['subAppId'] ?? "",
  108. // 'xcx_secret' => $input['xcxSecret'],
  109. 'group_id' => $input['groupId'],
  110. 'status' => $input['status'] ?? 1,
  111. 'remark' => $input['remark'] ?? ''
  112. ]);
  113. }
  114. $model->setWhere([['p.id' ,'=', (int)$id]]);
  115. $info = $model->getPayInfo();
  116. Until::output(['info' => $info]);
  117. }
  118. /**
  119. * @OA\GET(path="/api/Pay/read",
  120. * tags={"支付管理"},
  121. * summary="查看支付信息",
  122. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  123. * @OA\Parameter(name="id", in="query", description="支付id", @OA\Schema(type="ineger",default="1")),
  124. * @OA\RequestBody(
  125. * ),
  126. * @OA\Response(response="200", description="请求成功")
  127. * )
  128. */
  129. public function read($id) {
  130. $model = new PayModel();
  131. $where[] = ['p.id', '=', (int)$id];
  132. $model->setWhere($where);
  133. $info = $model->getPayInfo();
  134. Until::output(['info' => $info]);
  135. }
  136. /**
  137. * @OA\GET(path="/api/Pay/delete",
  138. * tags={"支付管理"},
  139. * summary="删除支付配置信息",
  140. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  141. * @OA\Parameter(name="id", in="query", description="支付id", @OA\Schema(type="ineger",default="1")),
  142. * @OA\Parameter(name="status", in="query", description="1正常 2删除", @OA\Schema(type="ineger",default="1")),
  143. * @OA\RequestBody(
  144. * ),
  145. * @OA\Response(response="200", description="请求成功")
  146. * )
  147. */
  148. public function delete($id, $status) {
  149. $model = new PayModel();
  150. $where[] = ['id', '=', (int)$id];
  151. $data = ['status' => (int)$status];
  152. $isSuccess = $model::where($where)->update($data);
  153. Until::output(['isSuccess' => $isSuccess]);
  154. }
  155. }