SpecialSource.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\special;
  12. use app\admin\model\special\Special as SpecialModel;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. /**
  16. * Class Special 专题素材关联表
  17. * @package app\admin\model\special
  18. */
  19. class SpecialSource extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /**获取专题素材
  23. * @param bool $special_id
  24. * @return false|\PDOStatement|string|\think\Collection
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. */
  29. public static function getSpecialSource($special_id = false, $source_id = false)
  30. {
  31. $where = array();
  32. $data = self::where($where);
  33. if ($special_id && is_numeric($special_id)) {
  34. $where['special_id'] = $special_id;
  35. $data->where($where);
  36. }
  37. if ($source_id) {
  38. if (!is_array($source_id)) {
  39. $where['source_id'] = $source_id;
  40. $data->where($where);
  41. } else {
  42. $data->whereIn('source_id', $source_id);
  43. }
  44. }
  45. return $data->order('sort desc')->select();
  46. }
  47. /**更新及添加专题素材
  48. * @param $source_list_ids 一维数组,素材id
  49. * @param int $special_id 专题id
  50. * @return bool
  51. */
  52. public static function saveSpecialSource($source_list_ids,$special_id=0,$special_type=1,$data=[])
  53. {
  54. if (!$special_id || !is_numeric($special_id)) {
  55. return false;
  56. }
  57. if (!$source_list_ids || !is_array($source_list_ids)) {
  58. return false;
  59. }
  60. try {
  61. $specialSourceAll = self::getSpecialSource($special_id)->toArray();
  62. if ($specialSourceAll) {
  63. self::where(['special_id' => $special_id])->delete();
  64. }
  65. $inster['special_id'] = $special_id;
  66. foreach ($source_list_ids as $sk => $sv) {
  67. if($special_type==SPECIAL_COLUMN){
  68. $special=SpecialModel::where('id',$sv->id)->field('pay_type,member_pay_type')->find();
  69. if($data['pay_type']==1 && $data['member_pay_type']==0){
  70. if($special['pay_type']==1 && $special['member_pay_type']==1){
  71. SpecialModel::where('id',$sv->id)->update(['member_pay_type'=>0,'member_money'=>0]);
  72. }
  73. $inster['pay_status'] = 1;
  74. }else if($data['pay_type']==0){
  75. if($special['pay_type']==1){
  76. SpecialModel::where('id',$sv->id)->update(['member_pay_type'=>0,'member_money'=>0,'pay_type'=>0,'money'=>0]);
  77. }
  78. $inster['pay_status'] = 0;
  79. }
  80. }else{
  81. $inster['pay_status'] = $sv->pay_status;
  82. }
  83. $inster['source_id'] = $sv->id;
  84. $inster['sort'] = $sv->sort;
  85. $inster['add_time'] = time();
  86. self::set($inster);
  87. }
  88. return true;
  89. } catch (\Exception $e) {
  90. return false;
  91. }
  92. }
  93. }