Form.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\form\api\controller;
  11. use app\api\controller\BaseApi;
  12. use addon\form\model\Form as FormModel;
  13. use app\model\goods\Goods;
  14. class Form extends BaseApi
  15. {
  16. /**
  17. * 获取商品表单数据
  18. * @return false|string
  19. */
  20. public function goodsForm()
  21. {
  22. if (!addon_is_exit('form', $this->site_id)) return $this->response( $this->success([]) );
  23. $goods_id = $this->params['goods_id'] ?? 0;
  24. $condition = [
  25. ['g.site_id', '=', $this->site_id ],
  26. ['g.goods_id', '=', $goods_id ],
  27. ['g.form_id', '>', 0 ],
  28. ['f.is_use', '=', 1 ]
  29. ];
  30. $data = (new Goods())->getGoodsInfo($condition, 'f.json_data', 'g', [ ['form f', 'g.form_id = f.id', 'left'] ])['data'];
  31. if (!empty($data)) {
  32. return $this->response( $this->success( json_decode($data['json_data'], true) ) );
  33. }
  34. return $this->response( $this->success($data) );
  35. }
  36. /**
  37. * 获取表单信息
  38. * @return false|string
  39. */
  40. public function info(){
  41. $form_id = $this->params['form_id'] ?? 0;
  42. $condition = [
  43. ['site_id', '=', $this->site_id ],
  44. ['id', '=', $form_id ],
  45. ['is_use', '=', 1 ],
  46. ['form_type', '=', 'custom' ]
  47. ];
  48. $data = (new FormModel())->getFormInfo($condition, 'json_data');
  49. if (!empty($data['data'])) {
  50. $data['data']['json_data'] = json_decode($data['data']['json_data'], true);
  51. }
  52. return $this->response($data);
  53. }
  54. /**
  55. * 添加表单数据
  56. * @return false|string
  57. */
  58. public function create(){
  59. $token = $this->checkToken();
  60. if ($token['code'] < 0) return $this->response($token);
  61. $form_id = $this->params['form_id'] ?? 0;
  62. $form_data = $this->params[ 'form_data' ] ?? '[]';
  63. $data = [
  64. 'site_id' => $this->site_id,
  65. 'form_id' => $form_id,
  66. 'member_id' => $this->member_id,
  67. 'relation_id' => 0,
  68. 'form_data' => json_decode($form_data, true),
  69. 'scene' => 'custom'
  70. ];
  71. $res = (new FormModel())->addFormData($data);
  72. return $this->response($res);
  73. }
  74. }