Sellertransport.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 卖家售卖地区控制器
  10. */
  11. class Sellertransport extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellertransport.lang.php');
  17. }
  18. public function index()
  19. {
  20. $this->transport_list();
  21. }
  22. /**
  23. * 返回商家店铺商品分类列表
  24. */
  25. public function transport_list()
  26. {
  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. } else {
  59. //新增
  60. $transport_id = $transport_model->addTransport($trans_info);
  61. }
  62. $trans_list = array();
  63. $special = input('post.transport_extend/a');
  64. if (is_array($special)) {
  65. foreach ($special as $key => $value) {
  66. if ($value) {
  67. if (!isset($value['transportext_is_default'])) {
  68. $value['transportext_is_default'] = 0;
  69. }
  70. if ($trans_info['transport_is_limited'] && $value['transportext_is_default']) {
  71. continue;
  72. }
  73. $tmp['transportext_top_area_id'] = $value['transportext_top_area_id'];
  74. $tmp['transportext_area_id'] = $value['transportext_area_id'];
  75. $tmp['transportext_area_name'] = $value['transportext_area_name'];
  76. $tmp['transportext_sprice'] = floatval($value['transportext_sprice']);
  77. $tmp['transport_id'] = $transport_id;
  78. $tmp['transport_title'] = $trans_info['transport_title'];
  79. $tmp['transportext_snum'] = intval($value['transportext_snum']);
  80. $tmp['transportext_xnum'] = intval($value['transportext_xnum']);
  81. $tmp['transportext_xprice'] = floatval($value['transportext_xprice']);
  82. $tmp['transportext_is_default'] = $value['transportext_is_default'];
  83. if ($tmp['transportext_is_default'] && $tmp['transportext_area_id']) {
  84. ds_json_encode(10001, lang('transportext_default_error'));
  85. }
  86. if (!$tmp['transportext_is_default'] && !$tmp['transportext_area_id']) {
  87. ds_json_encode(10001, lang('transportext_area_empty'));
  88. }
  89. $trans_list[] = $tmp;
  90. }
  91. }
  92. if (empty($trans_list)) {
  93. ds_json_encode(10001, lang('transportext_empty'));
  94. }
  95. } else {
  96. ds_json_encode(10001, lang('transportext_empty'));
  97. }
  98. $result = $transport_model->addExtend($trans_list);
  99. if ($result) {
  100. ds_json_encode(10000, '');
  101. } else {
  102. ds_json_encode(10001, lang('transport_op_fail'));
  103. }
  104. }
  105. public function del_transport()
  106. {
  107. $transport_id = intval(input('param.transport_id'));
  108. $transport_model = model('transport');
  109. $transport = $transport_model->getTransportInfo(array('transport_id' => $transport_id));
  110. if ($transport['store_id'] != session('store_id')) {
  111. ds_json_encode(10001, lang('transport_op_fail'));
  112. }
  113. //查看是否正在被使用
  114. if ($transport_model->isTransportUsing($transport_id)) {
  115. $this->error(lang('transport_op_using'));
  116. }
  117. if ($transport_model->delTansport($transport_id)) {
  118. ds_json_encode(10000, '');
  119. } else {
  120. ds_json_encode(10001, lang('transport_op_fail'));
  121. }
  122. }
  123. }