model = new \addons\shopro\model\split\Receiver; } public function index() { $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->custombuildparams(); $total = $this->model->where($where)->count(); $list = $this->model->where($where)->order($sort, $order)->limit($offset, $limit)->select(); return $this->success('操作成功', null, ['total' => $total, 'rows' => $list]); } return $this->view->fetch(); } public function add() { if ($this->request->isPost()) { $params = $this->request->post('row/a'); if (empty($params['receiver_account'])) { $this->error('请填写接收方账号'); } $this->model->create($params); $this->success('添加成功'); } return $this->view->fetch(); } public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error('记录不存在'); } if ($this->request->isPost()) { $params = $this->request->post('row/a'); $row->save($params); $this->success('保存成功'); } $this->view->assign('row', $row); return $this->view->fetch(); } public function del($ids = null) { $row = $this->model->get($ids); if ($row) { $row->status = 'forbidden'; $row->save(); } $this->success('操作成功'); } public function syncWx($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error('记录不存在'); } try { $service = new ProfitSharingService(); $service->addReceiver([ 'type' => $row['receiver_type'], 'account' => $row['receiver_account'], 'name' => $row['receiver_name'], 'relation_type' => $row['relation_type'] ?: 'USER', ]); $row->wx_status = 1; $row->wx_message = '同步成功'; $row->save(); $this->success('同步成功'); } catch (\Exception $e) { $row->wx_status = 2; $row->wx_message = $e->getMessage(); $row->save(); $this->error($e->getMessage()); } } }