Sellertransport.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 卖家售卖地区控制器
  14. */
  15. class Sellertransport extends MobileSeller {
  16. public function initialize() {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/sellertransport.lang.php');
  19. }
  20. public function index() {
  21. $this->transport_list();
  22. }
  23. /**
  24. * 返回商家店铺商品分类列表
  25. */
  26. public function transport_list() {
  27. $transport_model = model('transport');
  28. $transport_list = $transport_model->getTransportList(array('store_id' => $this->store_info['store_id']));
  29. ds_json_encode(10000, '',array('transport_list' => $transport_list));
  30. }
  31. public function edit_transport()
  32. {
  33. $id = intval(input('param.transport_id'));
  34. $transport_model = model('transport');
  35. $transport = $transport_model->getTransportInfo(array('transport_id' => $id));
  36. $extend = $transport_model->getExtendInfo(array('transport_id' => $id));
  37. ds_json_encode(10000, '',array('transport_info' => $transport,'transport_extend' => $extend));
  38. }
  39. public function save_transport()
  40. {
  41. $trans_info = array();
  42. $trans_info['transport_title'] = input('post.transport_title');
  43. $trans_info['send_tpl_id'] = 1;
  44. $trans_info['store_id'] = $this->store_info['store_id'];
  45. $trans_info['transport_updatetime'] = TIMESTAMP;
  46. $trans_info['transport_is_limited'] =intval(input('post.transport_is_limited'));
  47. $trans_info['transport_type'] =input('post.transport_type');
  48. $transport_model = model('transport');
  49. if(!$trans_info['transport_title']){
  50. ds_json_encode(10001, lang('transport_tpl_name_note'));
  51. }
  52. $transport_id = input('post.transport_id');
  53. if (is_numeric($transport_id)) {
  54. //编辑时,删除所有附加表信息
  55. $transport_id = intval($transport_id);
  56. $transport_model->editTransport($trans_info, array('transport_id' => $transport_id));
  57. $transport_model->delTransportextend($transport_id);
  58. }
  59. else {
  60. //新增
  61. $transport_id = $transport_model->addTransport($trans_info);
  62. }
  63. $trans_list = array();
  64. $special = input('post.transport_extend/a');
  65. if (is_array($special)) {
  66. foreach ($special as $key => $value) {
  67. if($value){
  68. if(!isset($value['transportext_is_default'])){
  69. $value['transportext_is_default']=0;
  70. }
  71. if($trans_info['transport_is_limited'] && $value['transportext_is_default']){
  72. continue;
  73. }
  74. $tmp['transportext_top_area_id'] = $value['transportext_top_area_id'];
  75. $tmp['transportext_area_id'] = $value['transportext_area_id'];
  76. $tmp['transportext_area_name'] = $value['transportext_area_name'];
  77. $tmp['transportext_sprice'] = floatval($value['transportext_sprice']);
  78. $tmp['transport_id'] = $transport_id;
  79. $tmp['transport_title'] = $trans_info['transport_title'];
  80. $tmp['transportext_snum'] = intval($value['transportext_snum']);
  81. $tmp['transportext_xnum'] = intval($value['transportext_xnum']);
  82. $tmp['transportext_xprice'] = floatval($value['transportext_xprice']);
  83. $tmp['transportext_is_default'] =$value['transportext_is_default'];
  84. if($tmp['transportext_is_default'] && $tmp['transportext_area_id']){
  85. ds_json_encode(10001, lang('transportext_default_error'));
  86. }
  87. if(!$tmp['transportext_is_default'] && !$tmp['transportext_area_id']){
  88. ds_json_encode(10001, lang('transportext_area_empty'));
  89. }
  90. $trans_list[] = $tmp;
  91. }
  92. }
  93. if(empty($trans_list)){
  94. ds_json_encode(10001, lang('transportext_empty'));
  95. }
  96. }else{
  97. ds_json_encode(10001, lang('transportext_empty'));
  98. }
  99. $result = $transport_model->addExtend($trans_list);
  100. if ($result) {
  101. ds_json_encode(10000, '');
  102. }
  103. else {
  104. ds_json_encode(10001, lang('transport_op_fail'));
  105. }
  106. }
  107. public function del_transport()
  108. {
  109. $transport_id = intval(input('param.transport_id'));
  110. $transport_model = model('transport');
  111. $transport = $transport_model->getTransportInfo(array('transport_id' => $transport_id));
  112. if ($transport['store_id'] != session('store_id')) {
  113. ds_json_encode(10001, lang('transport_op_fail'));
  114. }
  115. //查看是否正在被使用
  116. if ($transport_model->isTransportUsing($transport_id)) {
  117. $this->error(lang('transport_op_using'));
  118. }
  119. if ($transport_model->delTansport($transport_id)) {
  120. ds_json_encode(10000, '');
  121. }
  122. else {
  123. ds_json_encode(10001, lang('transport_op_fail'));
  124. }
  125. }
  126. }
  127. ?>