Express.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\express\ExpressCompany;
  12. use app\model\express\ExpressCompanyTemplate;
  13. use app\model\express\ExpressTemplate;
  14. use app\model\system\Address as AddressModel;
  15. use app\model\express\Kd100;
  16. use app\model\express\Kdbird;
  17. /**
  18. * 配送
  19. * Class Express
  20. * @package app\shop\controller
  21. */
  22. class Express extends BaseShop
  23. {
  24. public function __construct()
  25. {
  26. //执行父类构造函数
  27. parent::__construct();
  28. }
  29. /**
  30. * 物流公司
  31. * @return mixed
  32. */
  33. public function expressCompany()
  34. {
  35. if (request()->isAjax()) {
  36. $page = input('page', 1);
  37. $page_size = input('page_size', PAGE_LIST_ROWS);
  38. $search_text = input('search_text', '');
  39. $condition[] = [ 'site_id', '=', $this->site_id ];
  40. $condition[] = [ 'company_name', 'like', '%' . $search_text . '%' ];
  41. $order = 'is_electronicsheet desc,sort asc';
  42. $field = 'company_id,company_name,logo,sort,url,is_electronicsheet';
  43. $express_company_model = new ExpressCompanyTemplate();
  44. return $express_company_model->getExpressCompanyTemplatePageList($condition, $page, $page_size, $order, $field);
  45. } else {
  46. return $this->fetch('express/express_company');
  47. }
  48. }
  49. /**
  50. * 添加物流公司
  51. */
  52. public function addCompany()
  53. {
  54. $template_model = new ExpressCompanyTemplate();
  55. if (request()->isAjax()) {
  56. $data = [
  57. 'site_id' => $this->site_id,
  58. 'company_name' => input('company_name', ''),//物流公司名称
  59. 'sort' => input('sort', 0),//排序
  60. 'logo' => input('logo', ''),//logo
  61. 'url' => input('url', ''),//网址
  62. 'express_no' => input('express_no', ''),//编码
  63. 'express_no_kd100' => input('express_no_kd100', ''),//编码(快递100)
  64. 'express_no_cainiao' => input('express_no_cainiao', ''),//编码(菜鸟)
  65. 'content_json' => input('content_json', '[]'),//打印内容
  66. 'background_image' => input('background_image', ''),//打印背景图
  67. 'font_size' => input('font_size', 14),//打印字体大小 单位px
  68. 'width' => input('width', 0),//显示尺寸宽度 px
  69. 'height' => input('height', 0),//显示尺寸高度 px
  70. 'scale' => input('scale', 1),//真实尺寸(mm)与显示尺寸(px)的比例
  71. 'create_time' => time(),
  72. 'is_electronicsheet' => input('is_electronicsheet', 0),//是否支持电子面单
  73. 'print_style' => input('print_style', 0),//电子面单打印风格
  74. ];
  75. $res = $template_model->addExpressCompanyTemplate($data);
  76. if ($res[ 'code' ] >= 0) {
  77. $express_company_model = new ExpressCompany();
  78. $express_company_model->addExpressCompany([ 'site_id' => $this->site_id, 'company_id' => $res[ 'data' ] ]);
  79. $this->addLog("添加物流公司:" . $data[ 'company_name' ], $data);
  80. }
  81. return $res;
  82. } else {
  83. //打印项
  84. $print_item_list = $template_model->getPrintItemList();
  85. $this->assign('print_item_list', $print_item_list);
  86. return $this->fetch('express/add_company');
  87. }
  88. }
  89. /**
  90. * 物流公司编辑
  91. */
  92. public function editCompany()
  93. {
  94. $template_model = new ExpressCompanyTemplate();
  95. if (request()->isAjax()) {
  96. $data = [
  97. 'site_id' => $this->site_id,
  98. 'company_name' => input('company_name', ''),//物流公司名称
  99. 'sort' => input('sort', 0),//排序
  100. 'logo' => input('logo', ''),//logo
  101. 'url' => input('url', ''),//网址
  102. 'express_no' => input('express_no', ''),//编码
  103. 'express_no_kd100' => input('express_no_kd100', ''),//编码(快递100)
  104. 'express_no_cainiao' => input('express_no_cainiao', ''),//编码(菜鸟)
  105. 'content_json' => input('content_json', '[]'),//打印内容
  106. 'background_image' => input('background_image', ''),//打印背景图
  107. 'font_size' => input('font_size', 14),//打印字体大小 单位mm
  108. 'width' => input('width', 0),//显示尺寸宽度 px
  109. 'height' => input('height', 0),//显示尺寸高度 px
  110. 'scale' => input('scale', 1),//真实尺寸(mm)与显示尺寸(px)的比例
  111. 'modify_time' => time(),
  112. 'company_id' => input('company_id', 0),
  113. 'is_electronicsheet' => input('is_electronicsheet', 0),//是否支持电子面单
  114. 'print_style' => input('print_style', 0),//电子面单打印风格
  115. ];
  116. $res = $template_model->editExpressCompanyTemplate($data);
  117. if ($res[ 'code' ] == 0) {
  118. $express_company_model = new ExpressCompany();
  119. $express_company_model->editExpressCompany([
  120. 'content_json' => $data[ 'content_json' ],
  121. 'background_image' => $data[ 'background_image' ],
  122. 'font_size' => $data[ 'font_size' ],
  123. 'width' => $data[ 'width' ],
  124. 'height' => $data[ 'height' ]
  125. ], [ [ "site_id", "=", $this->site_id ], [ "company_id", "=", $data[ 'company_id' ] ] ]);
  126. }
  127. $this->addLog("编辑物流公司:" . $data[ 'company_name' ], $data);
  128. return $res;
  129. } else {
  130. //物流公司信息
  131. $company_id = input('company_id', 0);
  132. $company_info = $template_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $company_id ] ]);
  133. $this->assign('company_info', $company_info);
  134. //打印项
  135. $print_item_list = $template_model->getPrintItemList();
  136. $this->assign('print_item_list', $print_item_list);
  137. return $this->fetch('express/edit_company');
  138. }
  139. }
  140. public function deleteCompany()
  141. {
  142. if (request()->isAjax()) {
  143. $company_ids = input('company_ids', '');
  144. $template_model = new ExpressCompanyTemplate();
  145. $this->addLog("删除物流公司:" . $company_ids);
  146. $res = $template_model->deleteExpressCompanyTemplate([ [ 'company_id', 'in', $company_ids ] ]);
  147. if ($res[ 'code' ] == 0) {
  148. $express_company_model = new ExpressCompany();
  149. $express_company_model->deleteExpressCompany([ [ "site_id", "=", $this->site_id ], [ "company_id", "in", $company_ids ] ]);
  150. }
  151. return $res;
  152. }
  153. }
  154. /**
  155. * 修改物流公司排序
  156. */
  157. public function modifySort()
  158. {
  159. if (request()->isAjax()) {
  160. $sort = input('sort', 0);
  161. $company_id = input('company_id', 0);
  162. $express_company_model = new ExpressCompanyTemplate();
  163. return $express_company_model->modifyExpressCompanyTemplateSort($sort, $company_id);
  164. }
  165. }
  166. /**
  167. * 运费模板
  168. * @return mixed
  169. */
  170. public function template()
  171. {
  172. if (request()->isAjax()) {
  173. $express_template_model = new ExpressTemplate();
  174. $page = input('page', 1);
  175. $page_size = input('page_size', PAGE_LIST_ROWS);
  176. $order = input("order", "create_time desc");
  177. $keyword = input("keyword", '');
  178. $condition = array (
  179. [ 'site_id', "=", $this->site_id ],
  180. );
  181. //关键字查询
  182. if (!empty($keyword)) {
  183. $condition[] = [ "template_name", "like", "%" . $keyword . "%" ];
  184. }
  185. $result = $express_template_model->getExpressTemplatePageList($condition, $page, $page_size, $order);
  186. return $result;
  187. } else {
  188. return $this->fetch("express/template");
  189. }
  190. }
  191. /**
  192. * 添加运费模板
  193. * @return mixed
  194. */
  195. public function addTemplate()
  196. {
  197. if (request()->isAjax()) {
  198. $express_template_model = new ExpressTemplate();
  199. $fee_type = input("fee_type", '');//运费计算方式1.重量2体积3按件
  200. $template_name = input("template_name", '');
  201. $json = input("json", "");
  202. $is_default = input('is_default', 0);
  203. $surplus_area_ids = input('surplus_area_ids', '');
  204. $shipping_json = input('shipping_json', '');
  205. $shipping_surplus_area_ids = input('shipping_surplus_area_ids', '');
  206. $appoint_free_shipping = input('appoint_free_shipping', '0');
  207. if (empty($json))
  208. return error(-1, "模板配置不能为空!");
  209. $data = array (
  210. "fee_type" => $fee_type,
  211. "template_name" => $template_name,
  212. "site_id" => $this->site_id,
  213. 'is_default' => $is_default,
  214. 'surplus_area_ids' => $surplus_area_ids,
  215. 'shipping_surplus_area_ids' => $shipping_surplus_area_ids,
  216. 'appoint_free_shipping' => $appoint_free_shipping,
  217. );
  218. $json_data = json_decode($json, true);
  219. $shipping_json_data = json_decode($shipping_json, true);
  220. $result = $express_template_model->addExpressTemplate($data, $json_data, $shipping_json_data);
  221. return $result;
  222. } else {
  223. // 地区等级设置 将来从配置中查询数据
  224. $area_level = 4;
  225. // 计费方式
  226. $fee_type_obj = [
  227. '1' => [ 'name' => '按重量计费', 'snum' => '首重(Kg)', 'xnum' => '续重(Kg)' ],
  228. '2' => [ 'name' => '按体积计费', 'snum' => '首体积(m³)', 'xnum' => '续体积(m³)' ],
  229. '3' => [ 'name' => '按件计费', 'snum' => '首件(个)', 'xnum' => '续件(个)' ],
  230. ];
  231. $this->assign('fee_type_obj', $fee_type_obj);
  232. $this->assign('fee_type_json', json_encode($fee_type_obj));
  233. $this->assign('area_level', $area_level);//地址级别
  234. return $this->fetch("express/add_template");
  235. }
  236. }
  237. /**
  238. * 编辑运费模板
  239. * @return mixed
  240. */
  241. public function editTemplate()
  242. {
  243. $template_id = input("template_id", 0);
  244. $express_template_model = new ExpressTemplate();
  245. if (request()->isAjax()) {
  246. $fee_type = input("fee_type", '');//运费计算方式1.重量2体积3按件
  247. $template_name = input("template_name", '');
  248. $json = input("json", "");
  249. $is_default = input('is_default', 0);
  250. $surplus_area_ids = input('surplus_area_ids', '');
  251. $shipping_json = input('shipping_json', '');
  252. $shipping_surplus_area_ids = input('shipping_surplus_area_ids', '');
  253. $appoint_free_shipping = input('appoint_free_shipping', '0');
  254. if (empty($json))
  255. return error(-1, "模板配置不能为空!");
  256. $data = array (
  257. "fee_type" => $fee_type,
  258. "template_name" => $template_name,
  259. "site_id" => $this->site_id,
  260. "template_id" => $template_id,
  261. "is_default" => $is_default,
  262. 'surplus_area_ids' => $surplus_area_ids,
  263. 'shipping_surplus_area_ids' => $shipping_surplus_area_ids,
  264. 'appoint_free_shipping' => $appoint_free_shipping,
  265. );
  266. $json_data = json_decode($json, true);
  267. $shipping_json_data = json_decode($shipping_json, true);
  268. $result = $express_template_model->editExpressTemplate($data, $json_data, $shipping_json_data);
  269. return $result;
  270. } else {
  271. // 地区等级设置 将来从配置中查询数据
  272. $area_level = 4;
  273. // 计费方式
  274. $fee_type_obj = [
  275. '1' => [ 'name' => '按重量计费', 'snum' => '首重(Kg)', 'xnum' => '续重(Kg)' ],
  276. '2' => [ 'name' => '按体积计费', 'snum' => '首体积(m³)', 'xnum' => '续体积(m³)' ],
  277. '3' => [ 'name' => '按件计费', 'snum' => '首件(个)', 'xnum' => '续件(个)' ],
  278. ];
  279. $this->assign('fee_type_obj', $fee_type_obj);
  280. $this->assign('fee_type_json', json_encode($fee_type_obj));
  281. $this->assign('area_level', $area_level);//地址级别
  282. $info_result = $express_template_model->getExpressTemplateInfo($template_id, $this->site_id);
  283. $info = $info_result[ "data" ];
  284. $this->assign("info", $info);
  285. return $this->fetch("express/edit_template");
  286. }
  287. }
  288. /**
  289. * 删除运费模板
  290. * @return mixed
  291. */
  292. public function deleteTemplate()
  293. {
  294. if (request()->isAjax()) {
  295. $template_id = input("template_id", 0);
  296. $express_template_model = new ExpressTemplate();
  297. $result = $express_template_model->deleteExpressTemplate($template_id, $this->site_id);
  298. return $result;
  299. }
  300. }
  301. /**
  302. * 设置默认运费模板
  303. * @return mixed
  304. */
  305. public function defaultTemplate()
  306. {
  307. if (request()->isAjax()) {
  308. $template_id = input("template_id", 0);
  309. $express_template_model = new ExpressTemplate();
  310. $result = $express_template_model->updateDefaultExpressTemplate($template_id, 1, $this->site_id);
  311. return $result;
  312. }
  313. }
  314. /**
  315. * 通过ajax得到运费模板的地区数据
  316. */
  317. public function getAreaList()
  318. {
  319. if (request()->isAjax()) {
  320. $address_model = new AddressModel();
  321. $area_level = input('level', 4);
  322. $area_list = $address_model->getAddressTree($area_level)[ 'data' ];
  323. return $area_list;
  324. }
  325. }
  326. /**
  327. * 获取地区树结构
  328. */
  329. public function getAreaTree()
  330. {
  331. if (request()->isAjax()) {
  332. $address_model = new AddressModel();
  333. $area_level = input('level', 4);
  334. $area_list = $address_model->getAddressTreeList($area_level);
  335. return $area_list;
  336. }
  337. }
  338. /**
  339. * 查询可用物流公司
  340. */
  341. public function getShopExpressCompanyList()
  342. {
  343. if (request()->isAjax()) {
  344. $express_company_model = new ExpressCompany();
  345. // 店铺物流公司
  346. $condition = [
  347. [ "ec.site_id", "=", $this->site_id ]
  348. ];
  349. $field = 'ec.id, ec.company_id, ec.express_no, ec.content_json, ec.background_image, ec.font_size, ec.width, ec.height, ec.scale, ec.company_name';
  350. $order = 'ect.sort desc';
  351. $alias = 'ec';
  352. $join = [
  353. [ 'express_company_template ect', 'ec.company_id = ect.company_id', 'left' ]
  354. ];
  355. $result = $express_company_model->getExpressCompanyList($condition, $field, $order, $alias, $join);
  356. return $result;
  357. }
  358. }
  359. /**
  360. * 物流跟踪
  361. */
  362. public function trace()
  363. {
  364. $kd100_model = new Kd100();
  365. $kdbird_model = new Kdbird();
  366. if (request()->isAjax()) {
  367. $trace = input('traces_type', 'kd100');
  368. if ($trace == 'kd100') {
  369. $data = array (
  370. "appkey" => input("appkey", ""),
  371. "customer" => input("customer", ""),
  372. );
  373. $result = $kd100_model->setKd100Config($data, 1, $this->site_id);
  374. }
  375. if ($trace == 'kdbird') {
  376. $data = array (
  377. "EBusinessID" => input("EBusinessID", ""),
  378. "AppKey" => input("AppKey", ""),
  379. "status" => input("kdniao_status", 0),
  380. );
  381. $result = $kdbird_model->setKdbirdConfig($data, 1, $this->site_id);
  382. }
  383. return $result;
  384. } else {
  385. $kd100_config = $kd100_model->getKd100Config($this->site_id);
  386. $kdbird_config = $kdbird_model->getKdbirdConfig($this->site_id);
  387. $traces = [
  388. [
  389. 'name' => 'kd100',
  390. 'title' => '快递100',
  391. 'is_use' => $kd100_config[ 'data' ][ 'is_use' ]
  392. ],
  393. [
  394. 'name' => 'kdbird',
  395. 'title' => '快递鸟',
  396. 'is_use' => $kdbird_config[ 'data' ][ 'is_use' ]
  397. ]
  398. ];
  399. $this->assign('traces_type', $traces);
  400. $this->assign('kd100_config', $kd100_config[ "data" ]);
  401. $this->assign('kdbird_config', $kdbird_config[ "data" ]);
  402. return $this->fetch('express/trace');
  403. }
  404. }
  405. }