alias('drg') ->join('web_deliver_region dr', 'drg.deliver_region_id=dr.deliver_region_id') ->where($condition)->count(); $list = Db::name('deliver_region_logistics') ->alias('drg') ->join('web_deliver_region dr', 'drg.deliver_region_id=dr.deliver_region_id') ->field("drg.*,dr.region_code,dr.region_name")->where($condition)->order($order)->page($p, $other['page_size'])->select()->toArray(); // echo Db::getLastSql(); $other['count'] = $count; if (!$list) { $list = []; } // print_r($list); $result['other'] = $other; $result['list'] = $list; return $this->successResponse($result); } catch (Exception $exc) { return $this->errorResponse($exc->getMessage()); } } } /** *保存分销区域物流 */ public function save() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } //开始事务 Db::startTrans(); try { $data = Request::post(); $validate = new DeliverRegionLogisticsValidate(); $check_result = $validate->check($data); if (!$check_result) { return $this->errorResponse($validate->getError()); } $id = input('post.id'); if (is_numeric($id)) { //更新数据 $update_result = Db::name('deliver_region_logistics')->where('id', $id)->withoutField('id')->save($data); if ($update_result === FALSE) { return $this->errorResponse(lang('editing_failed')); } //提交事务 Db::commit(); return $this->successResponse('修改成功!'); } else { //添加数据 unset($data['id']); $add_result = Db::name('deliver_region_logistics')->insertGetId($data); if (!$add_result) { return $this->errorResponse('添加失败!'); } Db::name('deliver_region_logistics')->where('id', $add_result)->save(['order_id' => $add_result]); //提交事务 Db::commit(); return $this->successResponse('添加成功!'); } } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 删除分销区域物流 * @return array|int[] */ public function delete() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } //开始事务 Db::startTrans(); try { $id = input('id'); if (!is_numeric($id)) { return $this->errorResponse(lang('parameter_error')); } $condition['id'] = $id; $info = Db::name('deliver_region_logistics')->field('id')->where($condition)->find(); if (!$info) { return $this->errorResponse(lang('parameter_error')); } Db::name('deliver_region_logistics')->where('id', $id)->delete(); //提交事务 Db::commit(); return $this->successResponse('删除成功!'); } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } public function getDeliverRegionList() { try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $order = 'order_id asc'; $list = Db::name('deliver_region')->field("*")->order($order)->select()->toArray(); if ($list) { $result['list'] = $list; return $this->successResponse($result); } else { throw new Exception(lang('no_data_found')); } } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } }