Sellerspec.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /*
  3. * 店铺规格值
  4. * 每个店铺都有对应分类下保存的规格值
  5. */
  6. namespace app\api\controller;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Sellerspec extends MobileSeller
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerspec.lang.php');
  21. }
  22. /**
  23. * @api {POST} api/Sellerspec/save_spec 保存规格值
  24. * @apiVersion 1.0.0
  25. * @apiGroup Sellerspec
  26. *
  27. * @apiHeader {String} X-DS-KEY 卖家授权token
  28. *
  29. * @apiParam {Int} gc_id 商品分类ID
  30. * @apiParam {Object} spec_list 规格列表
  31. *
  32. * @apiSuccess {String} code 返回码,10000为成功
  33. * @apiSuccess {String} message 返回消息
  34. * @apiSuccess {Object} result 返回数据
  35. */
  36. public function save_spec()
  37. {
  38. $spec_list = input('post.spec_list/a');
  39. $gc_id = intval(input('post.gc_id'));
  40. if (empty($spec_list) || $gc_id <= 0) {
  41. ds_json_encode(10001, lang('param_error'));
  42. }
  43. $spec_model = model('spec');
  44. foreach ($spec_list as $sp_id => $spec) {
  45. $spvalue_ids = array();
  46. $specvalue_list = array();
  47. foreach ($spec['value'] as $val) {
  48. $val['spvalue_name'] = trim($val['spvalue_name']);
  49. if (!empty($val['spvalue_name'])) {
  50. if (isset($val['spvalue_id'])) {
  51. $spvalue_ids[] = $val['spvalue_id'];
  52. $condition = array();
  53. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  54. $condition[] = array('spvalue_id', '=', $val['spvalue_id']);
  55. $update = array(
  56. 'spvalue_name' => $val['spvalue_name'],
  57. );
  58. $spec_model->editSpecvalue($update, $condition);
  59. } else {
  60. $specvalue_list[] = array(
  61. 'spvalue_name' => $val['spvalue_name'],
  62. 'sp_id' => $sp_id,
  63. 'gc_id' => $gc_id,
  64. 'store_id' => $this->store_info['store_id'],
  65. 'spvalue_color' => '',
  66. 'spvalue_sort' => 255
  67. );
  68. }
  69. }
  70. }
  71. $condition = array();
  72. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  73. $condition[] = array('sp_id', '=', $sp_id);
  74. if (!empty($spvalue_ids)) {
  75. $condition[] = array('spvalue_id', 'not in', $spvalue_ids);
  76. }
  77. $spec_model->delSpecvalue($condition);
  78. if (!empty($specvalue_list)) {
  79. $spec_model->addSpecvalueALL($specvalue_list);
  80. }
  81. }
  82. ds_json_encode(10000, lang('ds_common_op_succ'));
  83. }
  84. }