| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * =========================================================
- */
- namespace addon\form\shop\controller;
- use addon\form\model\Form as FormModel;
- use addon\form\model\FormData as FormDataModel;
- use app\model\order\Order as OrderModel;
- use app\shop\controller\BaseShop;
- /**
- * 分销订单
- */
- class Form extends BaseShop
- {
- protected $replace = [
- 'FORM_JS' => __ROOT__ . '/addon/form/shop/view/public/js',
- 'FORM_CSS' => __ROOT__ . '/addon/form/shop/view/public/css',
- 'FORM_IMG' => __ROOT__ . '/addon/form/shop/view/public/img'
- ];
- public function __construct()
- {
- $this->app_module = input('app_module', SHOP_MODULE);
- if ($this->app_module == 'store') {
- $this->initConstructInfo(); // 加载构造函数重要信息
- } else {
- parent::__construct();
- }
- }
- /**
- * 编辑添加系统表单
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function editForm()
- {
- $from_model = new FormModel();
- if (request()->isAjax()) {
- $id = input('id', '');
- $form_name = input('form_name', '');
- $json_data = input('json_data', '');
- $data = [
- 'form_name' => $form_name,
- 'json_data' => $json_data,
- 'modify_time' => time()
- ];
- $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- }
- $id = input('id', '');
- $info = $from_model->getFormInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- if (empty($info[ 'data' ])) $this->error('未获取到表单数据');
- $this->assign('component', FormModel::FORM_COMPONENT);
- $this->assign('info', $info[ 'data' ]);
- $this->assign('form_type', ( new FormModel() )->form_type[ $info[ 'data' ][ 'form_type' ] ]);
- return $this->fetch('form/edit', [], $this->replace);
- }
- /**
- * 添加表单
- * @return array|mixed
- */
- public function addForm()
- {
- if (request()->isAjax()) {
- $form_name = input('form_name', '');
- $json_data = input('json_data', '');
- $form_type = input('form_type', 'order');
- $data = [
- 'form_name' => $form_name,
- 'json_data' => $json_data,
- 'form_type' => $form_type,
- 'site_id' => $this->site_id,
- 'create_time' => time(),
- 'is_use' => $form_type != 'order' ? 1 : 0
- ];
- $from_model = new FormModel();
- $res = $from_model->addForm($data);
- return $res;
- }
- $form_type = input('form_type', 'order');
- $this->assign('component', FormModel::FORM_COMPONENT);
- $this->assign('form_type', ( new FormModel() )->form_type[ $form_type ]);
- return $this->fetch('form/edit', [], $this->replace);
- }
- /**
- * 是否开启
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function editIsUse()
- {
- $from_model = new FormModel();
- $is_use = input('is_use', '');
- $id = input('id', '');
- $form_type = input('form_type', '');
- if (empty($is_use) && empty($id)) {
- $this->error('id和is_use不可为空');
- }
- //启用之前先把该类型的全都不启用
- if ($form_type == 'order') {
- $from_model->editForm([ 'is_use' => 0 ], [ [ 'form_type', '=', 'order' ], [ 'site_id', '=', $this->site_id ] ]);
- }
- $data = [
- 'is_use' => $is_use
- ];
- $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- }
- /**
- * 删除数据
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function deleteForm()
- {
- $id = input('id', '');
- if (empty($id)) {
- $this->error('id不可为空');
- }
- $from_model = new FormModel();
- $res = $from_model->deleteForm($id, $this->site_id);
- return $res;
- }
- /**
- * 表单列表
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function lists()
- {
- if (request()->isAjax()) {
- $form_type = input('form_type', '');
- $form_name = input('form_name', '');
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $is_use = input('is_use', '');
- $condition = [];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- if (!empty($form_type)) {
- $condition[] = [ 'form_type', '=', $form_type ];
- }
- if (!empty($form_name)) {
- $condition[] = [ 'form_name', 'like', '%' . $form_name . '%' ];
- }
- if (!empty($is_use)) {
- $condition[] = [ 'is_use', '=', $is_use ];
- }
- $from_model = new FormModel();
- $res = $from_model->getFormPageList($condition, $page, $page_size);
- return $res;
- }
- $this->assign('form_type', ( new FormModel() )->form_type);
- return $this->fetch('form/lists');
- }
- /**
- * 导出表单列表
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function exportForm()
- {
- $id = input('id', '');
- if (empty($id)) {
- $this->error('id不可为空');
- }
- $from_model = new FormModel();
- $res = $from_model->export([ 'id' => $id, 'site_id' => $this->site_id ]);
- if (isset($res[ 'code' ]) && $res[ 'code' ] != 0) $this->error($res[ 'message' ]);
- }
- /**
- * 获取详情
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function formInfo()
- {
- $id = input('id', '');
- $condition[] = [ 'site_id', '=', $this->site_id ];
- if (empty($id)) {
- $this->error('id不可为空');
- }
- $condition[] = [ 'id', '=', $id ];
- $from_model = new FormModel();
- $res = $from_model->getFormInfo($condition);
- return $res;
- }
- /**
- * 查看表单数据
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function formData()
- {
- $form_id = input('form_id', '');
- if (request()->isAjax()) {
- if (empty($form_id)) {
- $this->error('id不可为空');
- }
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $nickname = input('nickname', '');
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- $condition[] = [ 'fd.form_id', '=', $form_id ];
- $condition[] = [ 'fd.site_id', '=', $this->site_id ];
- if ($start_time && !$end_time) {
- $condition[] = [ 'fd.create_time', '>=', date_to_time($start_time) ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'fd.create_time', '<=', date_to_time($end_time) ];
- } elseif ($start_time && $end_time) {
- $condition[] = [ 'fd.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- if (!empty($nickname)) $condition[] = [ 'm.nickname', 'like', "%{$nickname}%" ];
- $alias = 'fd';
- $join = [
- [
- 'member m',
- 'fd.member_id = m.member_id',
- 'inner'
- ],
- ];
- $field = 'fd.*,m.headimg,m.nickname,m.status,m.member_level_type';
- $from_model = new FormDataModel();
- $res = $from_model->getFormDataPageList($condition, $field, 'fd.id desc', $page, $page_size, $alias, $join);
- if (!empty($res[ 'data' ][ 'list' ])) {
- $order_model = new OrderModel();
- foreach ($res[ 'data' ][ 'list' ] as $k => &$item_v) {
- $item_v[ 'form_data' ] = json_decode($item_v[ 'form_data' ], true);
- if ($item_v[ 'scene' ] == 'order') {
- $item_v[ 'order_info' ] = $order_model->getOrderInfo([ [ 'order_id', '=', $item_v[ 'relation_id' ] ] ], 'order_id,order_no')[ 'data' ];
- } elseif ($item_v[ 'scene' ] == 'goods') {
- $item_v[ 'order_goods_info' ] = $order_model->getOrderGoodsInfo([ [ 'order_goods_id', '=', $item_v[ 'relation_id' ] ] ], 'order_goods_id,order_id,order_no')[ 'data' ];
- }
- }
- }
- return $res;
- } else {
- $this->assign('form_id', $form_id);
- return $this->fetch('form/formdata', [], $this->replace);
- }
- }
- /**
- * 查询表单列表
- * @return array
- */
- public function getFormList()
- {
- if (request()->isAjax()) {
- $form_type = input('form_type', 'goods');
- $is_use = input('is_use', 1);
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'form_type', '=', $form_type ],
- [ 'is_use', '=', $is_use ]
- ];
- return ( new FormModel() )->getFormList($condition, 'id desc', 'id,form_name');
- }
- }
- /**
- * 推广
- * @return array
- */
- public function promote()
- {
- if (request()->isAjax()) {
- $form_id = input('form_id', '');
- $from_model = new FormModel();
- $res = $from_model->urlQrcode('/pages_tool/form/form', [ 'id' => $form_id ], $this->site_id);
- return $res;
- }
- }
- /**
- * 删除表单数据
- * @return array|string|string[]
- */
- public function deleteFormData()
- {
- if (request()->isAjax()) {
- $id = input('id', '');
- if (empty($id)) return error(-1, 'id不可为空');
- $from_model = new FormDataModel();
- $res = $from_model->deleteFormData([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- }
- }
- }
|