Material.php 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853
  1. <?php
  2. namespace app\sys\controller;
  3. use think\facade\Request;
  4. use think\facade\View;
  5. use think\facade\Db;
  6. use app\model\Community;
  7. use app\model\DailyWechatArticle;
  8. use app\model\Decostyle;
  9. use app\model\Designer;
  10. use app\model\MaterialEvidence;
  11. use app\model\MaterialCase;
  12. use app\model\MaterialEvidenceMedia;
  13. use app\model\DailyWechatLabel;
  14. use app\model\EvidenceCate;
  15. use app\model\Housetype;
  16. use app\model\Company;
  17. use app\model\Employee;
  18. use app\model\Org;
  19. use app\model\CreditsSetting;
  20. use app\model\Credits;
  21. use app\model\Construction;
  22. use app\model\Building;
  23. use app\model\User;
  24. use app\model\ShareLog;
  25. use app\model\Footprints;
  26. use app\model\CustomerClue;
  27. use app\model\VideoType;
  28. use app\model\Video;
  29. use app\model\Article;
  30. use app\model\CompanyStrengthCate;
  31. use app\model\CompanyStrength;
  32. use app\logics\MaterialLogic;
  33. use app\model\BuildingDevelopCase;
  34. use app\model\BuildingProgress;
  35. use app\model\BuildingHousetype;
  36. use app\model\BuildingMaterialCase;
  37. use app\model\CommunityImportLog;
  38. use app\logics\OrgLogic;
  39. use PhpOffice\PhpSpreadsheet\IOFactory;
  40. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  41. class Material
  42. {
  43. /**
  44. * 新建素材页面
  45. */
  46. public function index()
  47. {
  48. $condition = [['root_id', '=', request()->employee->root_id]];
  49. //小区名称获取
  50. $communities = Community::where($condition)->where([['type', '=', 0]])->select()->toArray();
  51. View::assign('communities', $communities);
  52. //设计师获取
  53. $designers = $this->get_designer();
  54. View::assign('designers', $designers);
  55. //风格获取
  56. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  57. View::assign('decostyles', $decostyles);
  58. //客户见证分类获取
  59. $cates = EvidenceCate::where($condition)->select()->toArray();
  60. View::assign('cates', $cates);
  61. //发圈分类获取
  62. $Wechatlabel = DailyWechatLabel::where($condition)->select();
  63. View::assign('Wechatlabel', $Wechatlabel);
  64. return View::fetch();
  65. }
  66. //获取设计师列表
  67. private function get_designer()
  68. {
  69. //设计师获取
  70. $w[] = ['path', 'like', request()->employee->root_id . '-%'];
  71. $w[] = ['org_type', '=', 2];
  72. $orgs = Org::where($w)->column('id');
  73. $list = Employee::where([['org_id', 'in', $orgs], ['state', '=', '在职'], ['show', '=', 0]])->field('id,name,initials s')->order('s asc')->select()->toArray();
  74. return $list;
  75. }
  76. /*
  77. * 案例添加视图页面
  78. */
  79. public function case_add()
  80. {
  81. $condition = [['root_id', '=', request()->employee->root_id]];
  82. //小区名称获取
  83. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  84. if (!empty($communities)) {
  85. $communities = hanziheadstr($communities);
  86. }
  87. View::assign('communities', $communities);
  88. //设计师获取
  89. $root_id = request()->employee->root_id;
  90. $list = $this->get_designer();
  91. if (!empty($list)) {
  92. // $list = hanziInitsort($list, 'name');
  93. $sort = array_column($list, 's');
  94. sort($sort);
  95. array_multisort($sort, SORT_ASC, $list);
  96. $sort = array_unique($sort);
  97. $list = ['sort' => $sort, 'arr' => $list];
  98. }
  99. View::assign('designers', $list);
  100. //风格获取
  101. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  102. View::assign('decostyles', $decostyles);
  103. //户型获取
  104. $housetype = Housetype::where($condition)->select()->toArray();
  105. View::assign('housetype', $housetype);
  106. $adding = input('adding', 0);
  107. view::assign('adding', $adding);
  108. return View::fetch();
  109. }
  110. public function evidence_add()
  111. {
  112. $condition = [['root_id', '=', request()->employee->root_id]];
  113. //客户见证分类获取
  114. $cates = EvidenceCate::where($condition)->select()->toArray();
  115. View::assign('cates', $cates);
  116. $adding = input('adding', 0);
  117. view::assign('adding', $adding);
  118. return View::fetch();
  119. }
  120. public function wxshow_add()
  121. {
  122. $condition = [['root_id', '=', request()->employee->root_id], ['from_type', '=', 0]];
  123. //发圈分类获取
  124. $Wechatlabel = DailyWechatLabel::where($condition)->select();
  125. View::assign('Wechatlabel', $Wechatlabel);
  126. $adding = input('adding', 0);
  127. view::assign('adding', $adding);
  128. return View::fetch();
  129. }
  130. /**
  131. * 添加/列表页面
  132. */
  133. public function __call($method, $arg)
  134. {
  135. if ($method == 'choiceadding') {
  136. $view = $arg['type'] . 'adding';
  137. } elseif ($method == 'wxshowlisting') {
  138. $eid = DailyWechatArticle::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
  139. $where = [
  140. ['id', 'in', $eid],
  141. ['grant_id', '>', 0],
  142. ['root_id', '=', request()->employee->root_id]
  143. ];
  144. // 运营人员列表
  145. $employee = Employee::where($where)->field(['id', 'opt_name as name'])->select()->toArray();
  146. View::assign('employee', $employee);
  147. //分类列表
  148. $label_list = DailyWechatLabel::where('root_id', request()->employee->root_id)->field('id,label_name')->select();
  149. View::assign('label_list', $label_list);
  150. $view = $method;
  151. } elseif ($method == 'community') {
  152. $view = $method;
  153. // 查询上传人
  154. $empIds = Community::where([['root_id', '=', request()->employee->root_id]])->column('employee_id');
  155. $employee = Employee::where([['id', 'in', $empIds]])->select();
  156. view::assign('employee', $employee);
  157. } else {
  158. $view = $method;
  159. }
  160. return View::fetch($view);
  161. }
  162. /**
  163. * 客户见证添加
  164. */
  165. public function apievidencesaving()
  166. {
  167. $data = input();
  168. $data['media_url'] = $data['oss_url'];
  169. $data['root_id'] = request()->employee->root_id;
  170. $obj = new MaterialEvidenceMedia();
  171. if ($obj->save($data))
  172. return json(['code' => 0, 'msg' => '保存成功', 'data' => $obj]);
  173. }
  174. /**
  175. * 添加小区页面
  176. */
  177. public function communityadding()
  178. {
  179. $id = input('id', '', 'intval');
  180. $info = [];
  181. if ($id) {
  182. $info = Community::where([['id', '=', $id], ['root_id', '=', request()->employee->root_id]])->findOrEmpty();
  183. $info['province'] = $info['city'] = $info['area'] = '';
  184. if (!$info->isEmpty()) {
  185. $location = !empty($info->location) ? explode('/', $info->location) : [];
  186. $info['province'] = !empty($location[0]) ? rtrim($location[0], '省') : '';
  187. $info['city'] = !empty($location[1]) ? rtrim($location[1], '市') : '';
  188. $info['area'] = !empty($location[2]) ? rtrim($location[2], '区') : '';
  189. }
  190. }
  191. View::assign('data', $info);
  192. View::assign('id', $id);
  193. return View::fetch();
  194. }
  195. /*
  196. * 案例小区添加
  197. */
  198. public function apicommunityadding()
  199. {
  200. $param = request()->only(['id', 'community', 'type', 'location' => '', 'duetime' => '']);
  201. if (!isset($param['community']) || !$param['community']) {
  202. return json(['code' => 1, 'msg' => '请输入小区名称']);
  203. } elseif (strlen($param['community']) > 60) {
  204. return json(['code' => 1, 'msg' => '小区名称过长']);
  205. }
  206. $condition = [
  207. 'root_id' => request()->employee->root_id
  208. ];
  209. if (isset($param['id']) && $param['id']) {
  210. $condition['id'] = $param['id'];
  211. } else {
  212. $condition['name'] = $param['community'];
  213. }
  214. $condition['type'] = isset($param['type']) ? $param['type'] : 0;
  215. $exitedobj = Community::where($condition)->findorEmpty();
  216. if (empty($param['id']) && !$exitedobj->isEmpty())
  217. return json(['code' => 1, 'msg' => '小区名称重复']);
  218. $pinyin = hanzi2pinyin($param['community']);
  219. $exitedobj->save([
  220. 'root_id' => request()->employee->root_id,
  221. 'pinyin' => $pinyin,
  222. 'name' => $param['community'],
  223. 'type' => isset($param['type']) ? $param['type'] : 0,
  224. 'initials' => strtoupper(substr($pinyin, 0, 1)),
  225. 'location' => $param['location'],
  226. 'duetime' => $param['duetime'] ? $param['duetime'] : null,
  227. 'employee_id' => request()->employee->id
  228. ]);
  229. return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $exitedobj->id, 'name' => $exitedobj->name]]);
  230. }
  231. /*
  232. * 案例设计师添加
  233. */
  234. public function apidesigneradding()
  235. {
  236. $data = input();
  237. if (!isset($data['designer-name']) || !$data['designer-name']) {
  238. return json(['code' => 1, 'msg' => '请输入设计师名称']);
  239. } elseif (strlen($data['designer-name']) > 45) {
  240. return json(['code' => 1, 'msg' => '设计师名称过长']);
  241. }
  242. $data['name'] = $data['designer-name'];
  243. $data['root_id'] = request()->employee->root_id;
  244. $exitedobj = Designer::where(['name' => $data['name'], 'root_id' => $data['root_id']])->find();
  245. if ($exitedobj)
  246. return json(['code' => 1, 'msg' => '设计师已存在']);
  247. unset($data['designer-name']);
  248. $obj = new Designer();
  249. if ($obj->save($data)) {
  250. return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $obj->id, 'name' => $obj->name]]);
  251. }
  252. }
  253. /*
  254. * 案例风格添加
  255. */
  256. public function apidecostyleadding()
  257. {
  258. $param = request()->only(['id', 'decostyle', 'type']);
  259. if (!isset($param['decostyle']) || !$param['decostyle']) {
  260. return json(['code' => 1, 'msg' => '请输入风格名称']);
  261. } elseif (strlen($param['decostyle']) > 45) {
  262. return json(['code' => 1, 'msg' => '风格名称过长']);
  263. }
  264. $condition = [
  265. 'root_id' => request()->employee->root_id
  266. ];
  267. if (isset($param['id']) && $param['id']) {
  268. $condition['id'] = $param['id'];
  269. } else {
  270. $condition['name'] = $param['decostyle'];
  271. }
  272. $condition['type'] = isset($param['type']) ? $param['type'] : 0;
  273. $exitedobj = Decostyle::where($condition)->findorEmpty();
  274. if (empty($param['id']) && !$exitedobj->isEmpty())
  275. return json(['code' => 1, 'msg' => '风格重复']);
  276. $exitedobj->save([
  277. 'root_id' => request()->employee->root_id,
  278. 'name' => $param['decostyle'],
  279. 'type' => isset($param['type']) ? $param['type'] : 0,
  280. ]);
  281. return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $exitedobj->id, 'name' => $exitedobj->name]]);
  282. }
  283. /*
  284. * 案例户型添加
  285. */
  286. public function apihousetypeadding()
  287. {
  288. $housetype_name = input('housetype-name');
  289. if (!$housetype_name) {
  290. return json(['code' => 1, 'msg' => '请输入户型名称']);
  291. } elseif (strlen($housetype_name) > 45) {
  292. return json(['code' => 1, 'msg' => '户型名称过长']);
  293. }
  294. $exitedobj = Housetype::where(['name' => $housetype_name, 'root_id' => request()->employee->root_id])->find();
  295. if ($exitedobj)
  296. return json(['code' => 1, 'msg' => '户型已存在']);
  297. $obj = new Housetype();
  298. $obj->save(['name' => $housetype_name, 'root_id' => request()->employee->root_id]);
  299. return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $obj->id, 'name' => $obj->name]]);
  300. }
  301. /*
  302. * 客户见证分类
  303. */
  304. public function apievidencecateadding()
  305. {
  306. $data = Request::only(['cate-name']);
  307. $data['name'] = $data['cate-name'];
  308. $data['root_id'] = request()->employee->root_id;
  309. $exitedobj = EvidenceCate::where(['name' => $data['name'], 'root_id' => $data['root_id']])->find();
  310. if ($exitedobj)
  311. return json(['code' => 1, 'msg' => '分类已存在']);
  312. unset($data['cate-name']);
  313. $obj = new EvidenceCate();
  314. if ($obj->save($data)) {
  315. return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $obj->id, 'name' => $obj->name]]);
  316. }
  317. }
  318. /*
  319. * 案例添加
  320. */
  321. public function apicaseadding()
  322. {
  323. $data = Request::only(['title', 'community_id', 'designer_id', 'style_id', 'housetype_id', 'square', 'room', 'hall', 'toilet', 'desc', 'cover_img', 'money', 'real_case', 'video_case', 'vr_case', 'video_type', 'recommend', 'cover_share_img', 'bh_type']);
  324. $data['root_id'] = request()->employee->root_id;
  325. $data['employee_id'] = request()->employee->id;
  326. $exitedobj = MaterialCase::where(['title' => $data['title'], 'root_id' => $data['root_id']])->find();
  327. if ($exitedobj)
  328. return json(['code' => 1, 'msg' => '案例标题已存在']);
  329. if (!empty($data['vr_case'])) {
  330. $data['vr_case'] = $this->vrlink_set($data['vr_case']);
  331. }
  332. $data['recommend'] = (isset($data['recommend']) && $data['recommend'] == 'on') ? 1 : 0;
  333. $community = Community::where('id', $data['community_id'])->find();
  334. if ($community == null) return json(['code' => 1, 'msg' => '小区不存在']);
  335. $data['housetype_type'] = $data['bh_type'] == 2 ? 'building_housetype' : 'housetype';
  336. $m = MaterialCase::create($data);
  337. $community->case_num = $community->case_num + 1;
  338. $community->save();
  339. // 楼盘
  340. $b = Building::where(['community_id' => $data['community_id']])->find();
  341. dataStatistics(request()->employee->root_id, 'case_count', 1, 'inc'); //manage应用首页统计数据
  342. return json(['code' => 0, 'msg' => '保存成功']);
  343. }
  344. /**
  345. * 文件上传
  346. */
  347. public function fileupload()
  348. {
  349. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  350. $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
  351. return json(['code' => 0, 'data' => ['src' => $url]]);
  352. }
  353. /*
  354. * 案例编辑保存
  355. */
  356. public function apicaseupdate()
  357. {
  358. $data = Request::only(['id', 'title', 'community_id', 'designer_id', 'style_id', 'housetype_id', 'square', 'room', 'hall', 'toilet', 'desc', 'cover_img', 'money', 'img_content', 'real_case', 'video_case', 'vr_case', 'video_type', 'recommend', 'cover_share_img', 'housetype_type']);
  359. $data['recommend'] = (isset($data['recommend']) && $data['recommend'] == 'on') ? 1 : 0;
  360. $exitedobj = MaterialCase::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find();
  361. if (!$exitedobj)
  362. return json(['code' => 1, 'msg' => '案例未创建']);
  363. $cover_img = $exitedobj->cover_img;
  364. if (!empty($data['img_content'])) {
  365. $img_content = array_filter(json_decode($data['img_content'], true));
  366. foreach ($img_content as $k => $v) {
  367. $domain = config('app.ali_oss_bindurl');
  368. $search = 'https://' . $domain . '/';
  369. $img_content[$k]['img'] = str_replace($search, '', $v['img']);
  370. // 封面默认为第一张图
  371. if ($k == 0) {
  372. $cover_img = str_replace($search, '', $v['img']);
  373. }
  374. }
  375. $data['img_content'] = json_encode($img_content);
  376. $data['cover_img'] = $cover_img;
  377. }
  378. if (!empty($data['cover_img'])) {
  379. $data['cover_img'] = str_replace('?x-oss-process=image/resize,l_125', '', $data['cover_img']);
  380. }
  381. if (!empty($data['cover_share_img'])) {
  382. $data['cover_share_img'] = str_replace('?x-oss-process=image/resize,l_125', '', $data['cover_share_img']);
  383. }
  384. if (!empty($data['vr_case'])) {
  385. $data['vr_case'] = $this->vrlink_set($data['vr_case']);
  386. }
  387. $param = $data;
  388. $data = array_filter($data, function ($v) {
  389. return ($v === '' || $v === null) ? false : true;
  390. });
  391. //非必传可以为空字段
  392. $fields = ['vr_case', 'money', 'desc', 'real_case', 'designer_id'];
  393. foreach ($fields as $v) {
  394. if (isset($param[$v])) $data[$v] = $param[$v];
  395. }
  396. unset($param);
  397. if ($exitedobj->save($data)) {
  398. return json(['code' => 0, 'msg' => '保存成功']);
  399. } else {
  400. return json(['code' => 1, 'msg' => '数据未改动']);
  401. }
  402. }
  403. //vr链接设置修改
  404. public function vrlink_set($vr_link)
  405. {
  406. //2023-05-04 app创建的vr作品
  407. if (strpos($vr_link, '/vr/#')) return $vr_link;
  408. // 旧域名 替换成 新域名
  409. $links = [
  410. 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com',
  411. 'kujiale' => 'pano337.p.kujiale.com',
  412. 'justeasy' => 'vr-17.justeasy.nczyzs.com',
  413. '3d66' => 'vr.3d66.nczyzs.com',
  414. ];
  415. $url = parse_url($vr_link);
  416. if ($url === false || !isset($url['host'])) {
  417. echo json_encode(['code' => 1, 'msg' => '链接格式错误']);
  418. exit;
  419. }
  420. if (strpos($url['host'], 'xiaohongwu') !== false) {
  421. return str_replace($url['host'], $links['xiaohongwu'], $vr_link);
  422. }
  423. if (strpos($url['host'], 'kujiale') !== false) {
  424. return str_replace($url['host'], $links['kujiale'], $vr_link);
  425. }
  426. if (strpos($url['host'], 'justeasy') !== false) {
  427. return str_replace($url['host'], $links['justeasy'], $vr_link);
  428. }
  429. if (strpos($url['host'], '3d66') !== false) {
  430. return str_replace($url['host'], $links['3d66'], $vr_link);
  431. }
  432. echo json_encode(['code' => 1, 'msg' => '无效的VR链接']);
  433. exit;
  434. }
  435. /*
  436. * 案例删除
  437. */
  438. public function apicasedelete()
  439. {
  440. $data = input();
  441. if (MaterialCase::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->update(['del' => 1])) {
  442. dataStatistics(request()->employee->root_id, 'case_count', 1, 'dec'); //manage应用首页统计数据
  443. return json(['code' => 0, 'msg' => '删除成功']);
  444. } else {
  445. return json(['code' => 1, 'msg' => '删除失败']);
  446. }
  447. }
  448. /*
  449. * 客户见证添加
  450. */
  451. public function apieviadding()
  452. {
  453. $data = Request::only(['title', 'desc', 'cate', 'evidence_image', 'pics', 'difference', 'cover' => '', 'video_type', 'cover_share_img']);
  454. //视频
  455. if ($data['difference'] == 1) {
  456. $data['pics'] = input('video_url', '');
  457. //图片
  458. } else {
  459. $data['pics'] = implode(',', $data['evidence_image']);
  460. unset($data['evidence_image']);
  461. }
  462. $data['root_id'] = request()->employee->root_id;
  463. $data['employee_id'] = request()->employee->id;
  464. $data['desc'] = isset($data['desc']) && $data['desc'] ? str_replace("\r\n", '', $data['desc']) : '';
  465. if (MaterialEvidence::create($data)) {
  466. return json(['code' => 0, 'msg' => '保存成功']);
  467. } else {
  468. return json(['code' => 1, 'msg' => '保存失败']);
  469. }
  470. }
  471. /*
  472. * 客户见证编辑保存
  473. */
  474. public function apieviupdate()
  475. {
  476. $data = Request::only(['id', 'title', 'cate', 'evidence_image_exist', 'evidence_image', 'desc', 'difference', 'cover', 'video_type', 'cover_share_img']);
  477. $data['cover'] = !isset($data['cover']) ? input('covers', '') : $data['cover'];
  478. //视频
  479. if ($data['difference'] == 1) {
  480. $video_url = input('video_url', '');
  481. $end = explode(',', $video_url);
  482. $data['pics'] = end($end);
  483. } else {
  484. $data['pics'] = '';
  485. if (isset($data['evidence_image_exist']) && is_array($data['evidence_image_exist'])) {
  486. $data['pics'] = implode(',', (array) $data['evidence_image_exist']);
  487. }
  488. if (isset($data['evidence_image']) && is_array($data['evidence_image'])) {
  489. $newpicsstr = implode(',', (array) $data['evidence_image']);
  490. if (!empty($data['pics'])) {
  491. $data['pics'] = $data['pics'] . ',' . $newpicsstr;
  492. } else {
  493. $data['pics'] = $newpicsstr;
  494. }
  495. }
  496. }
  497. unset($data['evidence_image_exist']);
  498. unset($data['evidence_image']);
  499. $data['desc'] = isset($data['desc']) && $data['desc'] ? str_replace("\r\n", '', $data['desc']) : '';
  500. $evidence = MaterialEvidence::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find();
  501. $evidence->save($data);
  502. return json(['code' => 0, 'msg' => '保存成功']);
  503. }
  504. /*
  505. * 客户见证删除
  506. */
  507. public function apievidelete()
  508. {
  509. $data = input();
  510. if (MaterialEvidence::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->update(['del' => 1])) {
  511. return json(['code' => 0, 'msg' => '删除成功']);
  512. } else {
  513. return json(['code' => 1, 'msg' => '删除失败']);
  514. }
  515. }
  516. public function apipublish()
  517. {
  518. $param = Request::param();
  519. $condition = ['id' => $param['id'], 'root_id' => request()->employee->root_id];
  520. switch ($param['cate']) {
  521. case 'case':
  522. $obj = MaterialCase::where($condition)->find();
  523. break;
  524. case 'evidence':
  525. $obj = MaterialEvidence::where($condition)->find();
  526. break;
  527. case 'wxshow':
  528. $obj = DailyWechatArticle::where($condition)->find();
  529. break;
  530. }
  531. if (empty($obj)) return json(['code' => 1, 'msg' => '数据不存在']);
  532. $obj->publish = $obj->publish == 1 ? 0 : 1;
  533. $obj->save();
  534. if ($param['cate'] == 'case') {
  535. if ($obj->publish) dataStatistics(request()->employee->root_id, 'case_count', 1, 'inc'); //manage应用首页统计数据
  536. //判断是否赠送过积分跟贡献值
  537. $you = Credits::where(['root_id' => request()->employee->root_id, 'employee_id' => $obj->employee_id, 'type' => 1, 'json' => 'upcaseid=' . $obj->id])->count();
  538. if (empty($you)) {
  539. $this->add_emp_integral($obj->employee_id, $obj->id);
  540. }
  541. }
  542. return json(['code' => 0, 'msg' => '修改成功']);
  543. }
  544. //增加业务员的贡献值跟积分
  545. public function add_emp_integral($empid, $id)
  546. {
  547. $request = request();
  548. $where[] = ['code', '=', 'material_case_value'];
  549. $where[] = ['root_id', '=', $request->employee->root_id];
  550. $data = CreditsSetting::where($where)->value('value');
  551. $material_case_value = 1;
  552. if (!empty($data)) {
  553. $material_case_value = $data;
  554. }
  555. if ($material_case_value) {
  556. $allgx = Credits::where(['root_id' => $request->employee->root_id, 'employee_id' => $empid, 'type' => 1])->sum('credits');
  557. Credits::create([
  558. 'employee_id' => $empid,
  559. 'root_id' => $request->employee->root_id,
  560. 'credits' => $material_case_value,
  561. 'sum' => $allgx + $material_case_value,
  562. 'type' => 1,
  563. 'json' => 'upcaseid=' . $id,
  564. 'remark' => '上传案例审核通过'
  565. ]);
  566. }
  567. }
  568. public function caselisting()
  569. {
  570. $styleList = Decostyle::where(['root_id' => request()->employee->root_id, 'type' => 0])->select();
  571. View::assign('decostyle', $styleList);
  572. $eid = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
  573. $w[] = ['id', 'in', $eid];
  574. $w[] = ['grant_id', '>', 0];
  575. $w[] = ['root_id', '=', request()->employee->root_id];
  576. // 运营人员列表
  577. $employee = Employee::where($w)->field(['id', 'opt_name as name'])->select()->toArray();
  578. View::assign('employee', $employee);
  579. $communityList = Community::where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select();
  580. if (!empty($communityList)) {
  581. $communityList = hanziheadstr($communityList->toArray());
  582. }
  583. View::assign('communityList', $communityList);
  584. return View::fetch();
  585. }
  586. public function personal_case_list()
  587. {
  588. $communityList = Community::where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select()->toArray();
  589. if (!empty($communityList)) {
  590. $communityList = hanziheadstr($communityList);
  591. }
  592. View::assign('communityList', $communityList);
  593. $list = $this->get_designer();
  594. if (!empty($list)) {
  595. $list = ['sort' => array_unique(array_column($list, 's')), 'arr' => $list];
  596. }
  597. View::assign('designers', $list);
  598. $employee_ids = MaterialCase::where([['root_id', '=', request()->employee->root_id], ['from', '=', 1], ['del', '=', 0]])->group('employee_id')->column('employee_id');
  599. $employee = Employee::where([['id', 'in', $employee_ids], ['state', '=', '在职']])->select();
  600. View::assign('employee', $employee);
  601. return View::fetch();
  602. }
  603. /*
  604. * 装修案例列表
  605. */
  606. public function caselist()
  607. {
  608. $param = Request::param();
  609. if (isset($param['title']) && $param['title']) {
  610. $where[] = ['title', 'like', '%' . trim($param['title']) . '%'];
  611. }
  612. // 小区搜索
  613. if (!empty($param['community'])) {
  614. $where[] = ['community_id', '=', $param['community']];
  615. }
  616. // 风格搜索
  617. if (!empty($param['decostyle'])) {
  618. $where[] = ['style_id', '=', $param['decostyle']];
  619. }
  620. //上传时间筛选
  621. if (!empty($param['add_time'])) {
  622. $newtime = explode(' - ', $param['add_time']);
  623. $start_time = $newtime[0] . ' 00:00:00';
  624. $end_time = $newtime[1] . ' 23:59:59';
  625. $where[] = ['addtime', 'between', [$start_time, $end_time]];
  626. }
  627. if (isset($param['designer_name']) && $param['designer_name']) {
  628. $designer_ids = Employee::where([['root_id', '=', request()->employee->root_id], ['name', 'like', '%' . $param['designer_name'] . '%']])->column('id');
  629. $where[] = ['designer_id', 'in', $designer_ids];
  630. }
  631. $order = 'recommend desc,addtime desc';
  632. if (!empty($param['order']) && in_array($param['order'], ['visit_due_time desc', 'visit_due_time asc', 'view_times asc', 'view_times desc', 'shared_times asc', 'shared_times desc'])) {
  633. $order = $param['order'];
  634. }
  635. $where[] = ['del', '=', 0];
  636. $where[] = ['root_id', '=', request()->employee->root_id];
  637. // 员工上传
  638. if (!empty($param['from'])) {
  639. $where[] = ['from', '=', 1];
  640. } else {
  641. $where[] = ['from', '=', 0];
  642. }
  643. if (!empty($param['employee_id'])) {
  644. $where[] = ['employee_id', '=', $param['employee_id']];
  645. }
  646. if (!empty($param['designer_id'])) {
  647. $where[] = ['designer_id', '=', $param['designer_id']];
  648. }
  649. $list = MaterialCase::with(['community', 'designer', 'decostyle', 'housetype', 'employee'])->where($where)->page($param['page'], $param['limit'])->order($order)->select();
  650. $list = $list->append(['housetype.name'])->toArray();
  651. $count = MaterialCase::where($where)->count();
  652. $footVisitTime = Footprints::where([
  653. ['pipe_type', '=', 'materialCase'],
  654. ['pipe_id', 'in', array_column($list, 'id')],
  655. ])->group('pipe_id')->column("sum(visit_due_time)", 'pipe_id');
  656. foreach ($list as $k => $item) {
  657. $list[$k]['visit_due_time'] = isset($footVisitTime[$item['id']]) ? $footVisitTime[$item['id']] : 0;
  658. }
  659. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  660. }
  661. public function evidencelisting()
  662. {
  663. $eid = MaterialEvidence::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
  664. $w[] = ['id', 'in', $eid];
  665. $w[] = ['grant_id', '>', 0];
  666. $w[] = ['root_id', '=', request()->employee->root_id];
  667. // 运营人员列表
  668. $employee = Employee::where($w)->field(['id', 'opt_name as name'])->select()->toArray();
  669. View::assign('employee', $employee);
  670. $cate_list = EvidenceCate::where('root_id', '=', request()->employee->root_id)->select();
  671. View::assign('cate_list', $cate_list);
  672. return View::fetch();
  673. }
  674. /*
  675. * 客户见证列表
  676. */
  677. public function evidencelist()
  678. {
  679. $param = Request::param();
  680. if (isset($param['title']) && $param['title']) {
  681. $where[] = ['title', 'like', '%' . trim($param['title']) . '%'];
  682. }
  683. if (!empty($param['cate'])) {
  684. $where[] = ['cate', '=', $param['cate']];
  685. }
  686. if (!empty($param['employee_id'])) {
  687. $where[] = ['employee_id', '=', $param['employee_id']];
  688. }
  689. //上传时间筛选
  690. if (!empty($param['add_time'])) {
  691. $newtime = explode(' - ', $param['add_time']);
  692. $start_time = $newtime[0] . ' 00:00:00';
  693. $end_time = $newtime[1] . ' 23:59:59';
  694. $where[] = ['addtime', 'between', [$start_time, $end_time]];
  695. }
  696. $order = 'addtime desc';
  697. if (!empty($param['order']) && in_array($param['order'], ['visit_due_time desc', 'visit_due_time asc', 'view_times asc', 'view_times desc', 'shared_times asc', 'shared_times desc'])) {
  698. $order = $param['order'];
  699. }
  700. $where[] = ['del', '=', 0];
  701. $where[] = ['root_id', '=', request()->employee->root_id];
  702. $list = MaterialEvidence::with(['cate', 'employee'])->where($where)->page($param['page'], $param['limit'])->order($order)->select();
  703. foreach ($list as &$item) {
  704. if (is_string($item->getData('pics'))) {
  705. $item['picsdata'] = explode(',', $item->getData('pics'));
  706. }
  707. if ($item['pics']) {
  708. $item['picnum'] = count($item['pics']);
  709. } else {
  710. $item['picnum'] = 0;
  711. }
  712. }
  713. //增加查询转发次数浏览时长
  714. // if(!empty($list->toArray())){
  715. // $statismod=new MaterialLogic;
  716. // $selorder=!empty($param['order'])?$param['order']:'';
  717. // $list=$statismod->sel_case_share($list->toArray(),'MaterialEvidence',$selorder);
  718. // }
  719. $count = MaterialEvidence::where($where)->count();
  720. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  721. }
  722. /*
  723. * 案例修改展示
  724. */
  725. public function casedetail()
  726. {
  727. $id = input('id');
  728. $data = MaterialCase::where(['id' => $id, 'root_id' => request()->employee->root_id])->with(['community', 'designer', 'decostyle', 'housetype'])->find();
  729. if (empty($data)) return '无效请求';
  730. if (!empty($data['img_content'])) {
  731. $img_content = json_decode($data['img_content'], true);
  732. foreach ($img_content as $k => $v) {
  733. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  734. $img_content[$k]['img'] = 'https://' . $ali_oss_bindurl . '/' . $v['img'];
  735. }
  736. $data['img_content'] = $img_content;
  737. }
  738. View::assign('data', $data);
  739. $condition = [['root_id', '=', request()->employee->root_id]];
  740. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  741. if (!empty($communities)) {
  742. $communities = hanziheadstr($communities);
  743. }
  744. View::assign('communities', $communities);
  745. $designers = $this->get_designer();
  746. if (!empty($designers)) {
  747. $sort = array_column($designers, 's');
  748. sort($sort);
  749. array_multisort($sort, SORT_ASC, $designers);
  750. $sort = array_unique($sort);
  751. $designers = ['sort' => $sort, 'arr' => $designers];
  752. // $designers = hanziInitsort($designers, 'name');
  753. }
  754. View::assign('designers', $designers);
  755. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  756. View::assign('decostyles', $decostyles);
  757. $housetype = Housetype::where($condition)->select()->toArray();
  758. View::assign('housetype', $housetype);
  759. if (isset($data['from']) && $data['from'] == 1) {
  760. return View::fetch('edit_personal_case');
  761. } else {
  762. return View::fetch();
  763. }
  764. }
  765. /*
  766. * 拓客案例预览api
  767. */
  768. public function preview_casedetail()
  769. {
  770. $id = input('id');
  771. $data = MaterialCase::where(['id' => $id, 'root_id' => request()->employee->root_id])->with(['community', 'designer', 'decostyle', 'housetype'])->find();
  772. if (!empty($data['img_content'])) {
  773. $img_content = json_decode($data['img_content'], true);
  774. foreach ($img_content as $k => $v) {
  775. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  776. $img_content[$k]['img'] = 'https://' . $ali_oss_bindurl . '/' . $v['img'];
  777. }
  778. $data['img_content'] = $img_content;
  779. }
  780. //公司信息
  781. $where[] = ['root_id', '=', request()->employee->root_id];
  782. $data['company_info'] = Company::where($where)->field('company_name,logo,company_address')->find();
  783. //设计师附属字段
  784. if ($data->designer) {
  785. $designer = Designer::where([['employee_id', '=', $data->designer_id], ['root_id', '=', request()->employee->root_id]])->field('id,good_at,position')->findOrEmpty();
  786. if ($designer->isEmpty()) {
  787. $data->designer->good_at = '';
  788. $data->designer->position = '';
  789. } else {
  790. $data->designer->good_at = !empty($designer->good_at) ? $designer->good_at : '';
  791. $data->designer->position = $designer->position ? $designer->position : '';
  792. }
  793. $data->designer->headimgurl = User::where('id', '=', $data->designer->uid)->value('headimgurl');
  794. }
  795. // 为null处理,防止前端报错
  796. $data['real_case'] = !empty($data['real_case']) ? $data['real_case'] : '';
  797. $data['desc'] = !empty($data['desc']) ? $data['desc'] : '';
  798. $data['vr_case'] = !empty($data['vr_case']) ? $data['vr_case'] : '';
  799. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  800. }
  801. /*
  802. * 客户见证编辑展示
  803. */
  804. public function evidencedetail()
  805. {
  806. $id = input('id');
  807. $evidence = MaterialEvidence::with('cate')->where(['id' => $id, 'root_id' => request()->employee->root_id])->field('*,cate cate_id')->find()->toArray();
  808. $evidence['pics'] = $evidence['difference'] == 1 ? $evidence['pics'][0] : $evidence['pics'];
  809. View::assign('evidence', $evidence);
  810. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  811. View::assign('ali_oss_bindurl', $ali_oss_bindurl);
  812. //客户见证分类获取
  813. $cates = EvidenceCate::where([['root_id', '=', request()->employee->root_id]])->select()->toArray();
  814. View::assign('cates', $cates);
  815. return View::fetch();
  816. }
  817. /*
  818. * 客户见证预览
  819. */
  820. public function preview_read()
  821. {
  822. $id = input('id', 0);
  823. $evidence = MaterialEvidence::with('cate')->where(['id' => $id, 'root_id' => request()->employee->root_id])->field('*,cate cate_id')->find()->toArray();
  824. $evidence['pics'] = $evidence['difference'] == 1 ? $evidence['pics'][0] : $evidence['pics'];
  825. //公司信息
  826. $where[] = ['root_id', '=', request()->employee->root_id];
  827. $evidence['company_info'] = Company::where($where)->field('company_name,logo,company_address')->find();
  828. return json(['code' => 0, 'msg' => '获取成功', 'data' => $evidence]);
  829. }
  830. /*
  831. * 每日发圈列表
  832. */
  833. public function wxshowlist()
  834. {
  835. $param = Request::param();
  836. if (isset($param['title']) && $param['title']) {
  837. $where[] = ['content', 'like', '%' . trim($param['title']) . '%'];
  838. }
  839. if (isset($param['employee_id']) && $param['employee_id']) {
  840. $where[] = ['employee_id', '=', $param['employee_id']];
  841. }
  842. if (isset($param['festival_id']) && $param['festival_id']) {
  843. $where[] = ['festival_id', '=', $param['festival_id']];
  844. }
  845. if (!empty($param['addtime'])) {
  846. list($start_date, $end_date) = explode(' - ', $param['addtime']);
  847. $where[] = ['addtime', '>=', $start_date];
  848. $where[] = ['addtime', '<=', date('Y-m-d H:i:s', strtotime($end_date) + 86400)];
  849. }
  850. $where[] = ['del', '=', 0];
  851. $where[] = ['root_id', '=', request()->employee->root_id];
  852. //$where[] = ['from_type', '=', 0];
  853. // 获取数据
  854. $list = DailyWechatArticle::where($where)->with(['dailyWechatLabel', 'employee'])->order('addtime desc,use_count desc')->page($param['page'], $param['limit'])->select();
  855. $count = DailyWechatArticle::where($where)->count();
  856. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  857. }
  858. /*
  859. * 每日发圈修改展示
  860. */
  861. public function wxshowdetail()
  862. {
  863. $id = input('id');
  864. $data = DailyWechatArticle::where(['id' => $id, 'root_id' => request()->employee->root_id])->find();
  865. $data->video = '';
  866. if ($data->type == 1) {
  867. $picture = $data->getData('picture');
  868. $arr = $data->picture;
  869. $data->video = ($picture == 'undefined' || !$picture) ? '' : end($arr);
  870. }
  871. View::assign('data', $data);
  872. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  873. // $ali_oss_bindurl = 'http://o.nczyzs.com/';
  874. View::assign('ali_oss_bindurl', $ali_oss_bindurl);
  875. $label = DailyWechatLabel::where([['root_id', '=', request()->employee->root_id], ['from_type', '=', 0]])->select();
  876. View::assign('label', $label);
  877. return View::fetch();
  878. }
  879. /**
  880. * 每日发圈修改保存
  881. */
  882. public function wxshowsave()
  883. {
  884. //Request中设置的有全局过滤规则trim,此处重新定义过滤规则(每次发圈开头不需要过滤)
  885. request()->filter([]);
  886. $data = Request::only(['content', 'article_image', 'article_image_exist', 'label', 'id', 'video_url', 'show_date']);
  887. $type = DailyWechatArticle::where('id', $data['id'])->value('type');
  888. // echo $type;
  889. if (empty($data['content'])) {
  890. return json(['code' => 1, 'msg' => '请输入内容']);
  891. }
  892. $inset = [
  893. 'festival_id' => !empty($data['label']) ? $data['label'] : 0,
  894. 'content' => $data['content'],
  895. // 'picture' => empty($data['article_image']) ? '' : implode(',', $data['article_image']),
  896. 'id' => $data['id'],
  897. 'show_date' => empty($data['show_date']) ? date('Y-m-d') : $data['show_date']
  898. ];
  899. if ($type == 1 && !empty($data['video_url'])) {
  900. $arr = explode(',', $data['video_url']);
  901. $inset['picture'] = end($arr);
  902. } elseif ($type == 2) {
  903. isset($data['article_image']) ?: $data['article_image'] = [];
  904. isset($data['article_image_exist']) ?: $data['article_image_exist'] = [];
  905. $data['article_image'] = array_merge($data['article_image'], $data['article_image_exist']);
  906. $inset['picture'] = empty($data['article_image']) ? '' : implode(',', $data['article_image']);
  907. }
  908. // var_dump($inset);die;
  909. // $inset['type'] = empty($inset['picture']) ? 3 : 2;
  910. DailyWechatArticle::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find()->save($inset);
  911. return json(['code' => 0, 'msg' => '修改成功']);
  912. }
  913. /*
  914. * 每日发圈分类添加
  915. */
  916. public function add_wechat_label()
  917. {
  918. $value = Request::param('value');
  919. $obj = DailyWechatLabel::create(['label_name' => $value, 'root_id' => request()->employee->root_id]);
  920. return json(['code' => 0, 'msg' => '添加成功', 'data' => ['id' => $obj->id, 'name' => $obj->label_name]]);
  921. }
  922. /*
  923. * 每日发圈添加
  924. */
  925. public function apiwxadding()
  926. {
  927. //Request中设置的有全局过滤规则trim,此处重新定义过滤规则(每次发圈开头不需要过滤)
  928. request()->filter([]);
  929. $data = Request::only(['type', 'content', 'video_url', 'article_image', 'label', 'show_date']);
  930. $inset = [
  931. 'festival_id' => !empty($data['label']) ? $data['label'] : 0,
  932. 'content' => $data['content'],
  933. // 'picture' => $data['type'] == 1 ? $data['video_url'] : ($data['type'] == 3 ? '' : implode(',', $data['article_image'])),
  934. // 'picture' => empty($data['article_image']) ? '' : implode(',', $data['article_image']),
  935. 'root_id' => request()->employee->root_id,
  936. 'type' => $data['type'],
  937. 'employee_id' => request()->employee->id,
  938. 'show_date' => empty($data['show_date']) ? date('Y-m-d') : $data['show_date']
  939. ];
  940. if ($data['type'] == 1) {
  941. $inset['picture'] = isset($data['video_url']) && $data['video_url'] ? $data['video_url'] : '';
  942. } elseif ($data['type'] == 2) {
  943. $inset['picture'] = empty($data['article_image']) ? '' : implode(',', $data['article_image']);
  944. if ($inset['picture']) {
  945. $img = explode(',', $inset['picture']);
  946. $imgs = [];
  947. foreach ($img as $v) {
  948. array_unshift($imgs, $v);
  949. }
  950. $inset['picture'] = implode(',', $imgs);
  951. }
  952. } else {
  953. $inset['picture'] = '';
  954. }
  955. DailyWechatArticle::insert($inset);
  956. return json(['code' => 0, 'msg' => '添加成功']);
  957. }
  958. /*
  959. * 每日发圈删除
  960. */
  961. public function apiwxdelete()
  962. {
  963. $data = input();
  964. Db::startTrans();
  965. try {
  966. $ms = DailyWechatArticle::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find(); //->update(['del' => 1]);
  967. //增加查询是否有指派
  968. $zp = DailyWechatArticle::where([['from_content_id', '=', $data['id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id]])->find();
  969. if (!empty($zp)) {
  970. //删除所有本文章的指派
  971. DailyWechatArticle::where([['from_content_id', '=', $data['id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id]])->update(['del' => 1]);
  972. //查询当前删除文章分类下是否有其它指派的文章
  973. $you = DailyWechatArticle::where([['festival_id', '=', $zp['festival_id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id], ['del', '=', 0]])->count();
  974. //如果没有就直接删除当前文章的指派分类
  975. if (empty($you)) {
  976. $obj = DailyWechatLabel::where([['id', '=', $zp['festival_id']], ['from_content_id', '=', $ms['festival_id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id]])->delete();
  977. }
  978. }
  979. $dl = DailyWechatArticle::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->update(['del' => 1]);
  980. Db::commit();
  981. } catch (\Exception $e) {
  982. Db::rollback();
  983. //var_dump($e->getMessage());
  984. return json(['code' => 1, 'msg' => '提交数据失败.']);
  985. }
  986. if ($dl) {
  987. return json(['code' => 0, 'msg' => '删除成功']);
  988. } else {
  989. return json(['code' => 1, 'msg' => '删除失败']);
  990. }
  991. }
  992. /*
  993. * VR
  994. */
  995. public function vr()
  996. {
  997. return View::fetch();
  998. }
  999. /*
  1000. * Vision 智能屏
  1001. */
  1002. public function vision()
  1003. {
  1004. return View::fetch();
  1005. }
  1006. /*
  1007. * 分类管理
  1008. */
  1009. function cate_administration($type)
  1010. {
  1011. view::assign('type', $type);
  1012. return View::fetch();
  1013. }
  1014. /*
  1015. * 素材案例分类管理列表
  1016. */
  1017. function cate_administration_list()
  1018. {
  1019. $param = Request::param();
  1020. $type = isset($param['type']) ? $param['type'] : 0;
  1021. $condition = [['root_id', '=', request()->employee->root_id]];
  1022. if (!empty($param['keyword'])) $condition[] = ['name', 'like', '%' . $param['keyword'] . '%'];
  1023. if (!empty($param['addtime'])) {
  1024. list($start_date, $end_date) = explode(' - ', $param['addtime']);
  1025. $condition[] = ['addtime', '>=', $start_date];
  1026. $condition[] = ['addtime', '<=', date('Y-m-d H:i:s', strtotime($end_date) + 86400)];
  1027. }
  1028. if (!empty($param['employee_id'])) {
  1029. $condition[] = ['employee_id', '=', $param['employee_id']];
  1030. }
  1031. if ($type == 0) {
  1032. //小区名称获取
  1033. $list = Community::with(['employee' => function ($query) {
  1034. $query->field(['id', 'opt_name']);
  1035. }])->where($condition)->where([['type', '=', 0]])->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->select();
  1036. $count = Community::where($condition)->where([['type', '=', 0]])->count();
  1037. } elseif ($type == 1) {
  1038. //风格获取
  1039. $list = Decostyle::where($condition)->where([['type', '=', 0]])->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->select()->toArray();
  1040. $count = Decostyle::where($condition)->where([['type', '=', 0]])->count();
  1041. } elseif ($type == 2) {
  1042. //户型获取
  1043. $list = Housetype::where($condition)->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->select()->toArray();
  1044. $count = Housetype::where($condition)->select()->count();
  1045. }
  1046. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  1047. }
  1048. /*
  1049. * 分类管理编辑
  1050. */
  1051. function cate_administration_edit()
  1052. {
  1053. $param = Request::param();
  1054. // return $param;
  1055. $type = isset($param['type']) ? $param['type'] : 0;
  1056. $conditions[] = ['id', '=', $param['id']];
  1057. $conditions[] = ['root_id', '=', request()->employee->root_id];
  1058. $condition[] = ['name', '=', $param['name']];
  1059. $condition[] = ['root_id', '=', request()->employee->root_id];
  1060. $data['name'] = $param['name'];
  1061. $province = !empty($param['province']) ? rtrim($param['province'], '省') . '省' : '';
  1062. $city = !empty($param['city']) ? rtrim($param['city'], '市') . '市' : '';
  1063. $area = !empty($param['area']) ? rtrim($param['area'], '区') . '区' : '';
  1064. if ($type == 0) {
  1065. $model = Community::where($condition);
  1066. $models = Community::where($conditions);
  1067. $data['pinyin'] = hanzi2pinyin($data['name']);
  1068. $data['initials'] = strtoupper(substr($data['pinyin'], 0, 1));
  1069. //$data['location'] = isset($param['location']) ? $param['location'] : '';
  1070. $data['location'] = $province . '/' . $city . '/' . $area;
  1071. $data['duetime'] = !empty($param['duetime']) ? $param['duetime'] : null;
  1072. $data['employee_id'] = request()->employee->id;
  1073. $data['households'] = input('households', 0);
  1074. $data['users'] = $param['users'];
  1075. //小区名称
  1076. } elseif ($type == 1) {
  1077. //风格
  1078. $model = Decostyle::where($condition);
  1079. $models = Decostyle::where($conditions);
  1080. } elseif ($type == 2) {
  1081. //户型获取
  1082. $model = Housetype::where($condition);
  1083. $models = Housetype::where($conditions);
  1084. }
  1085. $info = $model->find();
  1086. if ($info && $info['id'] != $param['id']) {
  1087. return json(['code' => 1, 'msg' => '名称已存在']);
  1088. }
  1089. $models->save($data);
  1090. return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
  1091. }
  1092. /*
  1093. * 分类管理添加
  1094. */
  1095. function cate_administration_add()
  1096. {
  1097. $param = Request::param();
  1098. // return $param;
  1099. $type = isset($param['type']) ? $param['type'] : 0;
  1100. $condition[] = ['name', '=', $param['name']];
  1101. $condition[] = ['root_id', '=', request()->employee->root_id];
  1102. $province = !empty($param['province']) ? rtrim($param['province'], '省') . '省' : '';
  1103. $city = !empty($param['city']) ? rtrim($param['city'], '市') . '市' : '';
  1104. $area = !empty($param['area']) ? rtrim($param['area'], '区') . '区' : '';
  1105. $data['name'] = $param['name'];
  1106. $data['root_id'] = request()->employee->root_id;
  1107. if ($type == 0) {
  1108. $model = Community::where($condition)->where([['type', '=', 0]]);
  1109. $models = new Community;
  1110. $data['pinyin'] = hanzi2pinyin($data['name']);
  1111. $data['initials'] = strtoupper(substr($data['pinyin'], 0, 1));
  1112. //$data['location'] = isset($param['location']) ? $param['location'] : '';
  1113. $data['location'] = $province . '/' . $city . '/' . $area;
  1114. $data['duetime'] = !empty($param['duetime']) ? $param['duetime'] : null;
  1115. $data['employee_id'] = request()->employee->id;
  1116. $data['households'] = input('households', 0);
  1117. $data['users'] = $param['users'];
  1118. //小区名称
  1119. } elseif ($type == 1) {
  1120. //风格
  1121. $model = Decostyle::where($condition)->where([['type', '=', 0]]);
  1122. $models = new Decostyle;
  1123. } elseif ($type == 2) {
  1124. //户型获取
  1125. $model = Housetype::where($condition);
  1126. $models = new Housetype;
  1127. }
  1128. $info = $model->find();
  1129. if ($info) {
  1130. return json(['code' => 1, 'msg' => '名称已存在']);
  1131. }
  1132. $models->save($data);
  1133. return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
  1134. }
  1135. /*
  1136. * 分类管理关联的数量
  1137. */
  1138. public function with_cate_administration_count()
  1139. {
  1140. $param = Request::param();
  1141. $type = isset($param['type']) ? $param['type'] : 0;
  1142. $msg = '确定删除该分类吗?';
  1143. $joinMsg = '';
  1144. if ($type == 0) {
  1145. //小区名称
  1146. $caseCount = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->count();
  1147. $caseCount > 0 ? $joinMsg .= $caseCount . '个拓客案例/' : '';
  1148. $buildingCount = Building::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->count();
  1149. $buildingCount > 0 ? $joinMsg .= $buildingCount . '个热装楼盘/' : '';
  1150. $constructionCount = Construction::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->count();
  1151. $constructionCount > 0 ? $joinMsg .= $constructionCount . '个在施工地/' : '';
  1152. if ($caseCount > 0 || $buildingCount > 0 || $constructionCount > 0) $msg = '该分类有' . $joinMsg . '删除后该内容将归为其它分类。';
  1153. } elseif ($type == 1) {
  1154. //风格
  1155. $caseCount = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->count();
  1156. $caseCount > 0 ? $joinMsg .= $caseCount . '个拓客案例/' : '';
  1157. $constructionCount = Construction::where([['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->count();
  1158. $constructionCount > 0 ? $joinMsg .= $constructionCount . '个在施工地/' : '';
  1159. if ($caseCount > 0 || $constructionCount > 0) $msg = '该分类有' . $joinMsg . '删除后该内容将归为其它分类。';
  1160. } elseif ($type == 2) {
  1161. //户型
  1162. $caseCount = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->count();
  1163. $caseCount > 0 ? $joinMsg .= $caseCount . '个拓客案例/' : '';
  1164. $constructionCount = Construction::where([['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->count();
  1165. $constructionCount > 0 ? $joinMsg .= $constructionCount . '个在施工地/' : '';
  1166. if ($caseCount > 0 || $constructionCount > 0) $msg = '该分类有' . $joinMsg . '删除后该内容将归为其它分类。';
  1167. }
  1168. return $msg;
  1169. }
  1170. /*
  1171. * 拓客案例分类删除
  1172. */
  1173. public function cate_administration_delete()
  1174. {
  1175. $param = Request::param();
  1176. $type = isset($param['type']) ? $param['type'] : 0;
  1177. Db::startTrans();
  1178. try {
  1179. if ($type == 0) {
  1180. //小区删除关联(拓客案例、热装楼盘、在施工地)
  1181. $community_id = Community::where(['root_id' => request()->employee->root_id, 'type' => 0, 'show' => 1])->value('id');
  1182. if (empty($community_id)) $community_id = Community::insertGetId(['name' => '其它', 'pinyin' => 'qita', 'root_id' => request()->employee->root_id, 'type' => 0, 'show' => 1]);
  1183. //删除标签
  1184. Community::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->delete();
  1185. //关联的标签更换为其它
  1186. MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->update(['community_id' => $community_id]);
  1187. Construction::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->update(['community_id' => $community_id]);
  1188. Building::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->update(['community_id' => $community_id]);
  1189. } elseif ($type == 1) {
  1190. //风格删除关联(拓客案例、在施工地)
  1191. $Decostyle_id = Decostyle::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id');
  1192. if (empty($Decostyle_id)) $Decostyle_id = Decostyle::insertGetId(['name' => '其它', 'root_id' => request()->employee->root_id, 'type' => 0, 'show' => 1]);
  1193. //删除标签
  1194. Decostyle::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->delete();
  1195. //关联的标签更换为其它
  1196. MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->update(['style_id' => $Decostyle_id]);
  1197. Construction::where([['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->update(['style_id' => $Decostyle_id]);
  1198. } elseif ($type == 2) {
  1199. //户型删除关联(拓客案例、在施工地)
  1200. $housetype_id = Housetype::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id');
  1201. if (empty($housetype_id)) $housetype_id = Housetype::insertGetId(['name' => '其它', 'root_id' => request()->employee->root_id, 'show' => 1]);
  1202. //删除标签
  1203. Housetype::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->delete();
  1204. //关联的标签更换为其它
  1205. MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->update(['housetype_id' => $housetype_id]);
  1206. Construction::where([['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->update(['housetype_id' => $housetype_id]);
  1207. }
  1208. Db::commit();
  1209. return json(['code' => 0, 'msg' => '操作成功']);
  1210. } catch (\Exception $e) {
  1211. Db::rollback();
  1212. return json(['code' => 1, 'msg' => '操作失败']);
  1213. }
  1214. }
  1215. /*
  1216. * 客户见证分类管理
  1217. */
  1218. function cate_customer()
  1219. {
  1220. return View::fetch();
  1221. }
  1222. /*
  1223. * 客户见证分类管理列表
  1224. */
  1225. function cate_customer_list()
  1226. {
  1227. $param = Request::param();
  1228. $condition = [['root_id', '=', request()->employee->root_id]];
  1229. $list = EvidenceCate::where($condition)->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->field('id,name,show')->select()->toarray();
  1230. $count = EvidenceCate::where($condition)->count();
  1231. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  1232. }
  1233. /*
  1234. * 客户见证分类管理添加
  1235. */
  1236. function cate_customer_add()
  1237. {
  1238. $param = Request::param();
  1239. $condition[] = ['name', '=', $param['name']];
  1240. $condition[] = ['root_id', '=', request()->employee->root_id];
  1241. $data['name'] = $param['name'];
  1242. $model = EvidenceCate::where($condition);
  1243. $models = new EvidenceCate;
  1244. $info = $model->find();
  1245. if ($info) {
  1246. return json(['code' => 1, 'msg' => '名称已存在']);
  1247. }
  1248. $models->name = $param['name'];
  1249. $models->root_id = request()->employee->root_id;
  1250. $models->save();
  1251. return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
  1252. }
  1253. /*
  1254. * 分类管理编辑
  1255. */
  1256. function cate_customer_edit()
  1257. {
  1258. $param = Request::param();
  1259. $conditions[] = ['id', '=', $param['id']];
  1260. $conditions[] = ['root_id', '=', request()->employee->root_id];
  1261. $condition[] = ['name', '=', $param['name']];
  1262. $condition[] = ['root_id', '=', request()->employee->root_id];
  1263. $data['name'] = $param['name'];
  1264. if (!$data['name']) {
  1265. return json(['code' => 1, 'msg' => '名称不能为空!']);
  1266. }
  1267. $model = EvidenceCate::where($condition);
  1268. $models = EvidenceCate::where($conditions);
  1269. $info = $model->find();
  1270. if ($info) {
  1271. return json(['code' => 1, 'msg' => '名称已存在']);
  1272. }
  1273. $models->update($data);
  1274. return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
  1275. }
  1276. /*
  1277. * 客户见证分类关联数量
  1278. */
  1279. public function with_evidence_cate_count()
  1280. {
  1281. $id = Request::param('id');
  1282. $where = [
  1283. ['root_id', '=', request()->employee->root_id],
  1284. ['del', '=', 0],
  1285. ['cate', '=', $id]
  1286. ];
  1287. $count = MaterialEvidence::where($where)->count();
  1288. return $count > 0 ? '该分类有' . $count . '个客户好评,删除后该内容将归为其它分类。' : '确定删除该分类吗?';
  1289. }
  1290. /*
  1291. * 客户见证分类删除
  1292. */
  1293. public function delete_evidence_cate()
  1294. {
  1295. $id = Request::param('id');
  1296. $cate_id = EvidenceCate::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id');
  1297. if (empty($cate_id)) $cate_id = EvidenceCate::insertGetId(['name' => '其它', 'root_id' => request()->employee->root_id, 'show' => 1]);
  1298. EvidenceCate::where(['root_id' => request()->employee->root_id, 'id' => $id])->delete();
  1299. $where = [
  1300. ['root_id', '=', request()->employee->root_id],
  1301. ['del', '=', 0],
  1302. ['cate', '=', $id]
  1303. ];
  1304. MaterialEvidence::where($where)->update(['cate' => $cate_id]);
  1305. return json(['code' => 0, 'msg' => '删除成功']);
  1306. }
  1307. /*
  1308. * 朋友圈分类管理
  1309. */
  1310. function cate_wechat()
  1311. {
  1312. //来源判断是集团后台还是店面后台
  1313. $from = request()->param('from');
  1314. View::assign('from', $from);
  1315. return View::fetch();
  1316. }
  1317. /*
  1318. * 朋友圈分类管理列表
  1319. */
  1320. function cate_wechat_list()
  1321. {
  1322. $param = Request::param();
  1323. $condition = [
  1324. ['root_id', '=', request()->employee->root_id]
  1325. // ['from_type', '=', 0]
  1326. ];
  1327. $list = DailyWechatLabel::where($condition)->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->field('id,label_name name,from_type,show')->select()->toArray();
  1328. //去掉集团指派的分类重复
  1329. foreach ($list as $key => $val) {
  1330. $xin[$val['from_type']][] = $val;
  1331. }
  1332. foreach ($xin as $key => $val) {
  1333. $p = $this->quchong($val);
  1334. $new[] = $p;
  1335. }
  1336. foreach ($new as $key => $val) {
  1337. foreach ($val as $k => $v) {
  1338. $s[] = $v[0];
  1339. }
  1340. }
  1341. $count = DailyWechatLabel::where($condition)->count();
  1342. return json(['code' => 0, 'data' => $s, 'count' => $count]);
  1343. }
  1344. public function quchong($val)
  1345. {
  1346. foreach ($val as $key => $val) {
  1347. $xin[$val['name']][] = $val;
  1348. }
  1349. return $xin;
  1350. }
  1351. /*
  1352. * 朋友圈分类管理添加
  1353. */
  1354. function cate_wechat_add()
  1355. {
  1356. $param = Request::param();
  1357. $condition[] = ['label_name', '=', $param['name']];
  1358. $condition[] = ['root_id', '=', request()->employee->root_id];
  1359. $condition[] = ['from_type', '=', 0]; //增加查询自建的分类
  1360. $data['label_name'] = $param['name'];
  1361. $model = DailyWechatLabel::where($condition);
  1362. $models = new DailyWechatLabel;
  1363. $info = $model->find();
  1364. if ($info) {
  1365. return json(['code' => 1, 'msg' => '名称已存在']);
  1366. }
  1367. $models->label_name = $param['name'];
  1368. $models->root_id = request()->employee->root_id;
  1369. $models->save();
  1370. return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
  1371. }
  1372. /*
  1373. * 朋友圈分类管理编辑
  1374. */
  1375. function cate_wechat_edit()
  1376. {
  1377. $param = Request::param();
  1378. $conditions[] = ['id', '=', $param['id']];
  1379. $conditions[] = ['root_id', '=', request()->employee->root_id];
  1380. $condition[] = ['label_name', '=', $param['name']];
  1381. $condition[] = ['root_id', '=', request()->employee->root_id];
  1382. $condition[] = ['from_type', '=', 0];
  1383. $data['label_name'] = $param['name'];
  1384. $model = DailyWechatLabel::where($condition);
  1385. $models = DailyWechatLabel::where($conditions);
  1386. $info = $model->find();
  1387. if ($info) {
  1388. return json(['code' => 1, 'msg' => '名称已存在']);
  1389. }
  1390. $models->update($data);
  1391. return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
  1392. }
  1393. /*
  1394. * 朋友圈分类删除时关联数量
  1395. */
  1396. public function cate_wechat_join_count()
  1397. {
  1398. $id = Request::param('id');
  1399. $where = [
  1400. ['root_id', '=', request()->employee->root_id],
  1401. ['festival_id', '=', $id]
  1402. ];
  1403. $count = DailyWechatArticle::where($where)->count();
  1404. return $count > 0 ? '该分类有' . $count . '个每日发圈,删除后该内容将归为其它分类。' : '确定删除该分类吗?';
  1405. }
  1406. /*
  1407. * 朋友圈分类删除
  1408. */
  1409. public function cate_wechat_delete()
  1410. {
  1411. $id = Request::param('id');
  1412. $cate_id = DailyWechatLabel::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id');
  1413. if (empty($cate_id)) $cate_id = DailyWechatLabel::insertGetId(['label_name' => '其它', 'root_id' => request()->employee->root_id, 'show' => 1]);
  1414. DailyWechatLabel::where(['root_id' => request()->employee->root_id, 'id' => $id])->delete();
  1415. $where = [
  1416. ['root_id', '=', request()->employee->root_id],
  1417. ['festival_id', '=', $id]
  1418. ];
  1419. DailyWechatArticle::where($where)->update(['festival_id' => $cate_id]);
  1420. return json(['code' => 0, 'msg' => '删除成功']);
  1421. }
  1422. /****************************集团后台板块开始*********************************/
  1423. /*
  1424. * 集团后台每日发圈数据列表
  1425. */
  1426. public function group_wechat_list()
  1427. {
  1428. $param = Request::param();
  1429. if (!Request::isAjax()) {
  1430. View::assign('root_id', isset($param['root_id']) ? $param['root_id'] : '');
  1431. return View::fetch();
  1432. }
  1433. $where = [
  1434. ['del', '=', 0],
  1435. ['from_type', '=', 0],
  1436. ['root_id', '=', request()->employee->root_id]
  1437. ];
  1438. if (isset($param['keyword'])) {
  1439. $where[] = ['content', 'like', '%' . trim($param['keyword']) . '%'];
  1440. }
  1441. // 获取数据
  1442. $list = DailyWechatArticle::where($where)->with(['dailyWechatLabel', 'employee'])->order('addtime desc,use_count desc')->page($param['page'], $param['limit'])->select()->toArray();
  1443. $ids = array_column($list, 'id');
  1444. $shareCompany = DailyWechatArticle::where([['from_type', '=', 1], ['from_content_id', 'in', $ids]])->group('from_content_id')->column('count(id)', 'from_content_id');
  1445. foreach ($list as &$v) {
  1446. $v['shareCompany'] = isset($shareCompany[$v['id']]) ? $shareCompany[$v['id']] : 0;
  1447. }
  1448. $count = DailyWechatArticle::where($where)->count();
  1449. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  1450. }
  1451. /*
  1452. * 共享的店面
  1453. */
  1454. public function groupShareCompany()
  1455. {
  1456. if (!Request::isAjax()) {
  1457. $id = request()->param('id');
  1458. view::assign('id', $id);
  1459. return View::fetch();
  1460. }
  1461. $id = request()->param('id');
  1462. $page = input('page', 1);
  1463. $limit = input('limit', 10);
  1464. $data = DailyWechatArticle::with(['company'])->where(['from_content_id' => $id, 'from_root_id' => request()->employee->root_id])->page($page, $limit)->select();
  1465. $count = DailyWechatArticle::with(['company'])->where(['from_content_id' => $id, 'from_root_id' => request()->employee->root_id])->count();
  1466. return json(['code' => 0, 'data' => $data, 'count' => $count]);
  1467. }
  1468. /*
  1469. * 指派
  1470. */
  1471. public function groupAssign()
  1472. {
  1473. $param = request()->param();
  1474. if (!Request::isAjax()) {
  1475. View::assign('id', $param['id']);
  1476. return View::fetch();
  1477. }
  1478. $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
  1479. $data = Company::where('company_group', $companyId)->field('root_id,company_name')->page($param['page'], $param['limit'])->select();
  1480. $count = Company::where('company_group', $companyId)->count();
  1481. return json(['code' => 0, 'data' => $data, 'count' => $count]);
  1482. }
  1483. /*
  1484. * 每日发圈指派
  1485. */
  1486. public function group_wechat_assign()
  1487. {
  1488. $param = request()->param();
  1489. //共享时查询关联数据
  1490. $wechat = DailyWechatArticle::where(['id' => $param['id'], 'root_id' => request()->employee->root_id])->find();
  1491. if (!$wechat) return json(['code' => 1, 'msg' => '数据不存在']);
  1492. $label = DailyWechatLabel::where('id', $wechat['festival_id'])->find();
  1493. Db::startTrans();
  1494. try {
  1495. $ids = explode(',', $param['ids']);
  1496. foreach ($ids as $v) {
  1497. //标签共享
  1498. //查询标签重复
  1499. $where = [];
  1500. $where[] = ['root_id', '=', $v];
  1501. $where[] = ['label_name', '=', $label['label_name']];
  1502. $check = DailyWechatLabel::where($where)->findOrEmpty();
  1503. if ($check->isEmpty()) {
  1504. $newLabel = DailyWechatLabel::insertGetId([
  1505. 'from_type' => 1,
  1506. 'from_root_id' => request()->employee->root_id,
  1507. 'from_content_id' => $label['id'],
  1508. 'label_name' => $label['label_name'],
  1509. 'root_id' => $v
  1510. ]);
  1511. } else {
  1512. $newLabel = $check->id;
  1513. }
  1514. unset($where);
  1515. //课程数据
  1516. $NewData = [
  1517. 'content' => $wechat['content'],
  1518. 'picture' => $wechat->getData('picture'),
  1519. 'type' => $wechat['type'],
  1520. 'festival_id' => $newLabel,
  1521. 'use_count' => 0,
  1522. 'publish' => 1,
  1523. 'employee_id' => $wechat['employee_id'],
  1524. 'root_id' => $v,
  1525. 'from_type' => 1,
  1526. 'from_root_id' => $wechat['root_id'],
  1527. 'from_content_id' => $wechat['id'],
  1528. ];
  1529. DailyWechatArticle::create($NewData);
  1530. }
  1531. Db::commit();
  1532. return json(['code' => 0, 'msg' => '操作成功']);
  1533. } catch (\Exception $e) {
  1534. Db::rollback();
  1535. return json(['code' => 1, 'msg' => '操作失败']);
  1536. }
  1537. }
  1538. /***************************集团后台板块结束**********************************/
  1539. /**
  1540. * 拓客案例数据统计页面
  1541. */
  1542. public function case_data_statistics($type = 0, $org_id = 0, $date = '')
  1543. {
  1544. $root_id = request()->employee->root_id;
  1545. if ($type) {
  1546. if ($org_id) {
  1547. $path = Org::where('id', $org_id)->value('path');
  1548. $org_where[] = ['path', 'like', $path . '%'];
  1549. $org_ids = Org::where($org_where)->column('id');
  1550. $eids = Employee::where([['org_id', 'in', $org_ids], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
  1551. } else {
  1552. $pid = Org::where([['path', 'like', $root_id . '-%']])->column('pid');
  1553. $org_ids = Org::where([['path', 'like', $root_id . '-%'], ['id', 'not in', $pid]])->column('id');
  1554. $em_where[] = ['root_id', '=', $root_id];
  1555. $em_where[] = ['uid', '>', 0];
  1556. $em_where[] = ['state', 'in', ['在职', '离职']];
  1557. $em_where[] = ['org_id', 'in', $org_ids];
  1558. $eids = Employee::where($em_where)->column('id');
  1559. }
  1560. if ($date) $date = explode(' - ', $date);
  1561. //案例总数
  1562. $case_where[] = ['root_id', '=', $root_id];
  1563. $case_where[] = ['del', '=', 0];
  1564. if (isset($eids)) $case_where[] = ['employee_id', 'in', $eids];
  1565. if ($date) $case_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1566. $case = MaterialCase::where($case_where)->column('view_times');
  1567. $data['case_count'] = count($case);
  1568. //浏览人数
  1569. $data['views'] = array_sum(array_filter($case));
  1570. //浏览人数 //浏览时长
  1571. $foot_where = [['pipe_type', '=', 'MaterialCase'], ['employee_id', 'in', $eids]];
  1572. if ($date) $foot_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1573. $footprint = Footprints::where($foot_where)->column('visit_due_time,uid');
  1574. // var_dump($foot_where);exit;
  1575. $data['times'] = array_sum(array_column($footprint, 'visit_due_time'));
  1576. $data['views'] = count(array_unique(array_column($footprint, 'uid')));
  1577. //转发次数
  1578. $share_where = [['employee_id', 'in', $eids], ['type', '=', 'MaterialCase']];
  1579. if ($date) $share_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1580. $shares = ShareLog::where($share_where)->column('employee_id');
  1581. $data['share_count'] = count($shares);
  1582. //转发人数
  1583. $data['share_group_count'] = count(array_unique($shares));
  1584. //获得线索
  1585. $clue_where = [['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']];
  1586. if ($date) $clue_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1587. $data['clue'] = CustomerClue::where($clue_where)->count();
  1588. return $data;
  1589. }
  1590. //父級部门
  1591. $pid = Org::where([['path', 'like', $root_id . '-%']])->column('pid');
  1592. $org = Org::where([['id', 'in', $pid]])->column('id,name');
  1593. View::assign('org', $org);
  1594. return View::fetch();
  1595. }
  1596. /**
  1597. * 拓客案例数据统计列表
  1598. */
  1599. public function case_data_statistics_list()
  1600. {
  1601. $root_id = request()->employee->root_id;
  1602. $param = Request()->only(['page' => 1, 'limit' => 10, 'date' => '', 'org_id' => 0]);
  1603. //父級部门
  1604. $pid = Org::where([['path', 'like', $root_id . '-%']])->column('pid');
  1605. $where[] = ['id', 'not in', $pid];
  1606. $where[] = ['path', 'like', $root_id . '-%'];
  1607. if ($param['org_id']) {
  1608. $path = Org::where('id', $param['org_id'])->value('path');
  1609. $where[] = ['path', 'like', $path . '%'];
  1610. }
  1611. $date_where = $share_date_where = [];
  1612. if ($param['date']) {
  1613. $date = explode(' - ', $param['date']);
  1614. $date_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1615. $share_date_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1616. }
  1617. //基层部门
  1618. $data = Org::with(['employee' => function ($query) {
  1619. $query->where('state', '在职')->field('id,org_id');
  1620. }])->where($where)->page($param['page'], $param['limit'])->order('id asc')->field('id,name')->select()->toArray();
  1621. //业务员
  1622. $em_where[] = ['root_id', '=', $root_id];
  1623. $em_where[] = ['uid', '>', 0];
  1624. $em_where[] = ['state', '=', '在职'];
  1625. $em_where[] = ['org_id', 'in', array_column($data, 'id')];
  1626. $eids = Employee::where($em_where)->column('id');
  1627. //转发人数,转发次数
  1628. $shares = ShareLog::where([['employee_id', 'in', $eids], ['type', '=', 'MaterialCase']])->where($share_date_where)->column('employee_id');
  1629. //浏览人数,浏览次数,浏览时长
  1630. $footprint = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->where($date_where)->column('employee_id,uid,visit_due_time');
  1631. $footprints = [];
  1632. foreach ($footprint as $val) {
  1633. //浏览人员
  1634. $footprints[$val['employee_id']]['employee'][] = $val['uid'];
  1635. //浏览时长
  1636. $val['visit_due_time'] = $val['visit_due_time'] ? $val['visit_due_time'] : 0;
  1637. isset($footprints[$val['employee_id']]['visit_due_time']) ? $footprints[$val['employee_id']]['visit_due_time'] += $val['visit_due_time'] : $footprints[$val['employee_id']]['visit_due_time'] = $val['visit_due_time'];
  1638. }
  1639. //线索
  1640. $clue = CustomerClue::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->where($date_where)->group('employee_id')->column('count(id) count', 'employee_id');
  1641. $res = [];
  1642. foreach ($data as $k => $v) {
  1643. $employee = array_intersect($shares, array_column($v['employee'], 'id'));
  1644. $share_count = count($employee);
  1645. $share_group_count = count(array_unique($employee));
  1646. $look_person = []; //浏览人员
  1647. $clue_count = 0; //线索数量
  1648. $visit_due_time = 0; //浏览时长
  1649. $employee_count = count($v['employee']); //部门人数
  1650. foreach ($v['employee'] as $k2 => $v2) {
  1651. if (isset($footprints[$v2['id']])) {
  1652. $look_person = array_merge($footprints[$v2['id']]['employee'], $look_person);
  1653. $visit_due_time += $footprints[$v2['id']]['visit_due_time'];
  1654. }
  1655. if (isset($clue[$v2['id']])) $clue_count += $clue[$v2['id']];
  1656. }
  1657. $res[] = [
  1658. 'id' => $v['id'],
  1659. 'org_name' => $v['name'],
  1660. 'share_count' => $share_count,
  1661. 'views' => count(array_unique($look_person)),
  1662. 'clue' => $clue_count,
  1663. 'visit_due_time' => $visit_due_time,
  1664. 'share_group_count' => $share_group_count,
  1665. 'no_share_count' => $employee_count - $share_group_count,
  1666. ];
  1667. }
  1668. $count = Org::where($where)->count();
  1669. $top_date = $this->case_data_statistics(1, $param['org_id'], $param['date']);
  1670. return json(['code' => 0, 'data' => $res, 'count' => $count, 'top_data' => $top_date]);
  1671. }
  1672. /**
  1673. * 拓客案例数据部门详情列表
  1674. */
  1675. public function case_datastatistics_org()
  1676. {
  1677. $org_id = input('org_id', 0);
  1678. View::assign('org_id', $org_id);
  1679. return View::fetch();
  1680. }
  1681. /**
  1682. * 拓客案例数据部门详情列表
  1683. */
  1684. public function case_datastatistics_org_list()
  1685. {
  1686. $param = Request()->only(['org_id' => 0, 'page' => 1, 'limit' => 10, 'keyword' => '', 'date' => '']);
  1687. $root_id = request()->employee->root_id;
  1688. $em_where[] = ['root_id', '=', $root_id];
  1689. $em_where[] = ['uid', '>', 0];
  1690. $em_where[] = ['state', '=', '在职'];
  1691. $em_where[] = ['org_id', '=', $param['org_id']];
  1692. if ($param['keyword']) $em_where[] = ['name', 'like', '%' . trim($param['keyword']) . '%'];
  1693. $res = Employee::where($em_where)->page($param['page'], $param['limit'])->column('id,name');
  1694. $count = Employee::where($em_where)->count();
  1695. $eids = array_column($res, 'id');
  1696. $date_where = $share_date_where = [];
  1697. if ($param['date']) {
  1698. $date = explode(' - ', $param['date']);
  1699. $date_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1700. $share_date_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1701. }
  1702. //转发人数,转发次数
  1703. $shares = ShareLog::where([['employee_id', 'in', $eids], ['type', '=', 'MaterialCase']])->where($share_date_where)->column('employee_id');
  1704. //浏览人数
  1705. // $footprints = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->where($date_where)->group('employee_id')->column('count(id) count,sum(visit_due_time) visit_due_time', 'employee_id');
  1706. //浏览人数,浏览次数,浏览时长
  1707. $footprint = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->where($date_where)->column('employee_id,uid,visit_due_time');
  1708. $footprints = [];
  1709. foreach ($footprint as $val) {
  1710. //浏览人员
  1711. $footprints[$val['employee_id']]['employee'][] = $val['uid'];
  1712. //浏览时长
  1713. $val['visit_due_time'] = $val['visit_due_time'] ? $val['visit_due_time'] : 0;
  1714. isset($footprints[$val['employee_id']]['visit_due_time']) ? $footprints[$val['employee_id']]['visit_due_time'] += $val['visit_due_time'] : $footprints[$val['employee_id']]['visit_due_time'] = $val['visit_due_time'];
  1715. }
  1716. //线索
  1717. $clue = CustomerClue::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->where($date_where)->group('employee_id')->column('count(id) count', 'employee_id');
  1718. $data = [];
  1719. foreach ($res as $k => $v) {
  1720. $employee = array_intersect($shares, [$v['id']]);
  1721. $data[] = [
  1722. 'id' => $v['id'],
  1723. 'name' => $v['name'],
  1724. 'share_count' => count($employee),
  1725. 'views' => isset($footprints[$v['id']]) ? count(array_unique($footprints[$v['id']]['employee'])) : 0,
  1726. 'clue' => isset($clue[$v['id']]) ? $clue[$v['id']] : 0,
  1727. 'visit_due_time' => isset($footprints[$v['id']]) ? $footprints[$v['id']]['visit_due_time'] : 0
  1728. ];
  1729. }
  1730. return json(['code' => 0, 'data' => $data, 'count' => $count, 'page' => $param]);
  1731. }
  1732. /**
  1733. * 拓客案例数据统计人员统计详情页面
  1734. */
  1735. public function case_datastatistics_org_read()
  1736. {
  1737. $eid = input('eid', 0);
  1738. View::assign('eid', $eid);
  1739. return View::fetch();
  1740. }
  1741. /**
  1742. * 拓客案例数据统计人员统计详情页面
  1743. */
  1744. public function case_datastatistics_org_read_list()
  1745. {
  1746. $param = Request()->only(['eid' => 0, 'page' => 1, 'limit' => 10, 'keyword' => '', 'date' => '']);
  1747. $root_id = request()->employee->root_id;
  1748. $where[] = ['employee_id', '=', $param['eid']];
  1749. $where[] = ['type', '=', 'MaterialCase'];
  1750. if ($param['keyword']) {
  1751. $keyword_where[] = ['root_id', '=', $root_id];
  1752. $keyword_where[] = ['title', 'like', '%' . trim($param['keyword']) . '%'];
  1753. $mids = MaterialCase::where($keyword_where)->column('id');
  1754. $where[] = ['data_id', 'in', $mids];
  1755. }
  1756. $ids = ShareLog::where($where)->group('data_id')->column('data_id');
  1757. if (empty($ids)) return json(['code' => 0, 'data' => [], 'count' => 0]);
  1758. $query[] = ['id', 'in', $ids];
  1759. //标题
  1760. $data = MaterialCase::where($query)->page($param['page'], $param['limit'])->column('title,id');
  1761. $count = MaterialCase::where($query)->count();
  1762. $ids = array_column($data, 'id');
  1763. $share_where = $date_where = [];
  1764. if ($param['date']) {
  1765. $date = explode(' - ', $param['date']);
  1766. $share_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1767. $date_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']];
  1768. }
  1769. //分享次数
  1770. $shares = ShareLog::where([['data_id', 'in', $ids], ['type', '=', 'MaterialCase']])->where($share_where)->group('data_id')->column('count(id) count', 'data_id');
  1771. //获得线索
  1772. $clue = CustomerClue::where([['pipe_id', 'in', $ids], ['pipe_type', '=', 'materialCase']])->where($date_where)->group('pipe_id')->column('count(id) count', 'pipe_id');
  1773. //浏览时长,浏览次数
  1774. $foot_where[] = ['pipe_type', '=', 'materialCase'];
  1775. $foot_where[] = ['employee_id', '=', $param['eid']];
  1776. $where_ids = [];
  1777. foreach ($ids as $v) {
  1778. $where_ids[] = '{"id":' . $v . '%';
  1779. }
  1780. $foot_where[] = ['reg_info', 'like', $where_ids, 'OR'];
  1781. $footprints = Footprints::where($foot_where)->where($date_where)->column('reg_info,visit_due_time');
  1782. $views = [];
  1783. $time = [];
  1784. foreach ($footprints as $v2) {
  1785. $json = json_decode($v2['reg_info'], true);
  1786. $views[$json['id']][] = $json['id'];
  1787. if ($v2['visit_due_time']) {
  1788. isset($time[$json['id']]) ? $time[$json['id']] += $v2['visit_due_time'] : $time[$json['id']] = $v2['visit_due_time'];
  1789. }
  1790. }
  1791. $res = [];
  1792. foreach ($data as $k3 => $v3) {
  1793. //浏览人数,浏览时长
  1794. $res[] = [
  1795. 'title' => $v3['title'],
  1796. 'id' => $v3['id'],
  1797. 'share_count' => isset($shares[$v3['id']]) ? $shares[$v3['id']] : 0,
  1798. 'view_count' => isset($views[$v3['id']]) ? count($views[$v3['id']]) : 0,
  1799. 'visit_due_time' => isset($time[$v3['id']]) ? $time[$v3['id']] : 0,
  1800. 'clue' => isset($clue[$v3['id']]) ? $clue[$v3['id']] : 0
  1801. ];
  1802. }
  1803. return json(['code' => 0, 'data' => $res, 'count' => $count]);
  1804. }
  1805. //客户好评数据统计列表
  1806. public function evidence_statistics_data_list()
  1807. {
  1808. $request = request();
  1809. $param = $request->only(['page' => 1, 'limit' => 10, 'org_id', 'time']);
  1810. if (!request()->isAjax()) {
  1811. $list = orgSubIds(request()->employee->root_id);
  1812. $xins = [];
  1813. foreach ($list as $key => $val) {
  1814. if (Org::where([['pid', '=', $val], ['status', '=', 1]])->value('id')) {
  1815. $xins[] = $val;
  1816. }
  1817. }
  1818. $orglist = Org::where([['id', 'in', $xins]])->field('id,name,pid')->select()->toArray();
  1819. view::assign('orglist', $orglist);
  1820. return view::fetch();
  1821. }
  1822. if (!empty($param['org_id'])) {
  1823. $list = orgSubIds($param['org_id']);
  1824. } else {
  1825. $list = orgSubIds(request()->employee->root_id);
  1826. }
  1827. $xin = [];
  1828. foreach ($list as $key => $val) {
  1829. if (!Org::where([['pid', '=', $val], ['status', '=', 1]])->value('id')) {
  1830. $xin[] = $val;
  1831. }
  1832. }
  1833. $newlist = Org::with(['employee' => function ($sql) {
  1834. $sql->where([['state', '=', '在职'], ['uid', '<>', 0]])->field('id,org_id');
  1835. }])->where([['id', 'in', $xin]])->field('id,name,pid')->page($param['page'], $param['limit'])->select()->toArray();
  1836. $clue_type = 'materialEvidence';
  1837. $share_type = 'MaterialEvidence';
  1838. $orgid = array_column($newlist, 'id');
  1839. $empid = Employee::where([['org_id', 'in', $orgid], ['state', '=', '在职'], ['uid', '<>', 0]])->column('id');
  1840. //转发人数
  1841. if (!empty($param['time'])) {
  1842. $newtime = explode(' - ', $param['time']);
  1843. $start_time = $newtime[0] . ' 00:00:00';
  1844. $end_time = $newtime[1] . ' 23:59:59';
  1845. $where[] = ['share_time', 'between', [$start_time, $end_time]];
  1846. $clue_where[] = ['addtime', 'between', [$start_time, $end_time]];
  1847. $foot_where[] = ['addtime', 'between', [$start_time, $end_time]];
  1848. }
  1849. $where[] = ['type', '=', $share_type];
  1850. $where[] = ['employee_id', 'in', $empid];
  1851. $clue_where[] = ['employee_id', 'in', $empid];
  1852. $clue_where[] = ['pipe_type', '=', $clue_type];
  1853. $foot_where[] = ['employee_id', 'in', $empid];
  1854. $foot_where[] = ['pipe_type', '=', $clue_type];
  1855. $shared_employee = ShareLog::where($where)->column('employee_id');
  1856. $clue_count = CustomerClue::where($clue_where)->column('employee_id');
  1857. $foot_data = Footprints::where($foot_where)->field('id,employee_id,uid,visit_due_time')->select()->toArray();
  1858. $new = [];
  1859. foreach ($foot_data as $key => $val) {
  1860. $new[$val['employee_id']][] = $val;
  1861. }
  1862. foreach ($newlist as $key => $val) {
  1863. $empids = array_column($val['employee'], 'id');
  1864. $newlist[$key]['share_count'] = count(array_intersect($shared_employee, $empids));
  1865. $yes_share_count = count(array_unique(array_intersect($shared_employee, $empids)));
  1866. $newlist[$key]['share_employee_count'] = $yes_share_count;
  1867. $newlist[$key]['clue_count'] = count(array_intersect($clue_count, $empids));
  1868. $cont = $visit_due_time = $uid = 0;
  1869. foreach ($new as $k => $v) {
  1870. if (in_array($k, $empids)) {
  1871. $cont += count($v);
  1872. $visit_due_time += array_sum(array_column($v, 'visit_due_time'));
  1873. $uid += count(array_unique(array_column($v, 'uid')));
  1874. }
  1875. }
  1876. $newlist[$key]['footprints_count'] = $cont;
  1877. $newlist[$key]['visit_long'] = $visit_due_time;
  1878. $newlist[$key]['footprints_user_count'] = $uid;
  1879. $un_share_employee = count($empids) - $yes_share_count;
  1880. $newlist[$key]['un_share_employee_count'] = $un_share_employee;
  1881. }
  1882. $count = Org::where([['id', 'in', $xin]])->count();
  1883. $all = $this->top_statistics_data($xin, !empty($param['time']) ? $param['time'] : 0);
  1884. $data = ['list' => $newlist, 'all' => $all];
  1885. return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]);
  1886. }
  1887. public function top_statistics_data($xin, $time = 0)
  1888. {
  1889. $evidence_cont = MaterialEvidence::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id]])->count();
  1890. $all = ['evidence_cont' => $evidence_cont, 'share_employee_count' => 0, 'share_count' => 0, 'clue_count' => 0, 'footprints_count' => 0, 'visit_long' => 0, 'footprints_user_count' => 0, 'un_share_employee_count' => 0];
  1891. $sub_employee_ids = Employee::where([['org_id', 'in', $xin], ['state', '=', '在职'], ['uid', '<>', 0]])->column('id');
  1892. $clue_type = 'materialEvidence';
  1893. $share_type = 'MaterialEvidence';
  1894. //转发人数
  1895. if (!empty($time)) {
  1896. $newtime = explode(' - ', $time);
  1897. $start_time = $newtime[0] . ' 00:00:00';
  1898. $end_time = $newtime[1] . ' 23:59:59';
  1899. $where[] = ['share_time', 'between', [$start_time, $end_time]];
  1900. $clue_where[] = ['addtime', 'between', [$start_time, $end_time]];
  1901. $foot_where[] = ['addtime', 'between', [$start_time, $end_time]];
  1902. }
  1903. $em_where[] = ['employee_id', 'in', $sub_employee_ids];
  1904. $where[] = ['type', '=', $share_type];
  1905. //$where[] = ['employee_id', 'in', $sub_employee_ids];
  1906. $shared_employee = ShareLog::where($where)->where($em_where)->column('employee_id');
  1907. // 转发次数
  1908. $all['share_count'] = count($shared_employee);
  1909. $all['share_employee_count'] = count(array_values(array_unique($shared_employee)));
  1910. // 获得线索
  1911. //$clue_where[] = ['employee_id', 'in', $sub_employee_ids];
  1912. $clue_where[] = ['pipe_type', '=', $clue_type];
  1913. $clue_count = CustomerClue::where($clue_where)->where($em_where)->count();
  1914. $all['clue_count'] = $clue_count;
  1915. // 浏览次数
  1916. //$foot_where[] = ['employee_id', 'in', $sub_employee_ids];
  1917. $foot_where[] = ['pipe_type', '=', $clue_type];
  1918. $foot_user_count = Footprints::where($foot_where)->where($em_where)->field('id,uid,visit_due_time')->select()->toArray();
  1919. $all['footprints_user_count'] = count(array_unique(array_column($foot_user_count, 'uid')));
  1920. // 浏览时长
  1921. $all['visit_long'] = array_sum(array_column($foot_user_count, 'visit_due_time'));
  1922. return $all;
  1923. }
  1924. //统计员工列表
  1925. public function statistics_emplist()
  1926. {
  1927. $request = request();
  1928. $param = $request->only(['page' => 1, 'limit' => 10, 'keyword', 'org_id', 'time']);
  1929. if (!request()->isAjax()) {
  1930. view::assign('org_id', $param['org_id']);
  1931. return view::fetch();
  1932. }
  1933. $e_where[] = ['org_id', '=', $param['org_id']];
  1934. $e_where[] = ['state', '=', '在职'];
  1935. $e_where[] = ['uid', '<>', 0];
  1936. if (!empty($param['keyword'])) {
  1937. $e_where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
  1938. }
  1939. $employee_list = Employee::where($e_where)->field('id,name')->page($param['page'], $param['limit'])->select()->toArray();
  1940. $clue_type = 'materialEvidence';
  1941. $share_type = 'MaterialEvidence';
  1942. $empid = array_column($employee_list, 'id');
  1943. if (!empty($param['time'])) {
  1944. $newtime = explode(' - ', $param['time']);
  1945. $start_time = $newtime[0] . ' 00:00:00';
  1946. $end_time = $newtime[1] . ' 23:59:59';
  1947. $where[] = ['share_time', 'between', [$start_time, $end_time]];
  1948. $clue_where[] = ['addtime', 'between', [$start_time, $end_time]];
  1949. $foot_where[] = ['addtime', 'between', [$start_time, $end_time]];
  1950. }
  1951. $where[] = ['type', '=', $share_type];
  1952. $where[] = ['employee_id', 'in', $empid];
  1953. $clue_where[] = ['employee_id', 'in', $empid];
  1954. $clue_where[] = ['pipe_type', '=', $clue_type];
  1955. $foot_where[] = ['employee_id', 'in', $empid];
  1956. $foot_where[] = ['pipe_type', '=', $clue_type];
  1957. $shared_employee = ShareLog::where($where)->column('employee_id');
  1958. $clue_count = CustomerClue::where($clue_where)->column('employee_id');
  1959. $foot_data = Footprints::where($foot_where)->field('id,employee_id,uid,visit_due_time')->select()->toArray();
  1960. $new = [];
  1961. foreach ($foot_data as $key => $val) {
  1962. $new[$val['employee_id']][] = $val;
  1963. }
  1964. foreach ($employee_list as $key => $val) {
  1965. $empids = [$val['id']];
  1966. $employee_list[$key]['share_count'] = count(array_intersect($shared_employee, $empids));
  1967. $yes_share_count = count(array_unique(array_intersect($shared_employee, $empids)));
  1968. $employee_list[$key]['share_employee_count'] = $yes_share_count;
  1969. $employee_list[$key]['clue_count'] = count(array_intersect($clue_count, $empids));
  1970. $cont = $visit_due_time = $uid = 0;
  1971. foreach ($new as $k => $v) {
  1972. if (in_array($k, $empids)) {
  1973. $cont += count($v);
  1974. $visit_due_time += array_sum(array_column($v, 'visit_due_time'));
  1975. $uid += count(array_unique(array_column($v, 'uid')));
  1976. }
  1977. }
  1978. $employee_list[$key]['footprints_count'] = $cont;
  1979. $employee_list[$key]['visit_long'] = $visit_due_time;
  1980. $employee_list[$key]['footprints_user_count'] = $uid;
  1981. $un_share_employee = count($empids) - $yes_share_count;
  1982. $employee_list[$key]['un_share_employee_count'] = $un_share_employee;
  1983. }
  1984. $count = Employee::where($e_where)->count();
  1985. return json(['code' => 0, 'msg' => '获取成功', 'data' => $employee_list, 'count' => $count]);
  1986. }
  1987. //统计员工转发记录详情列表
  1988. public function emp_logdetail_list()
  1989. {
  1990. $request = request();
  1991. $param = $request->only(['page' => 1, 'limit' => 10, 'keyword', 'emp_id', 'time']);
  1992. if (!request()->isAjax()) {
  1993. view::assign('emp_id', $param['emp_id']);
  1994. return view::fetch();
  1995. }
  1996. $empid = $param['emp_id'];
  1997. $share_list = $this->sel_emp_videolist($empid);
  1998. if (!empty($param['keyword'])) {
  1999. $key_list = MaterialEvidence::where([['root_id', '=', request()->employee->root_id], ['title', 'like', '%' . $param['keyword'] . '%']])->column('id');
  2000. if (!empty($key_list) && !empty($share_list)) {
  2001. $tm = array_intersect($key_list, $share_list);
  2002. if (!empty($tm)) {
  2003. $share_list = $tm;
  2004. } else {
  2005. return json(['code' => 0, 'msg' => '获取成功', 'data' => [], 'count' => 0]);
  2006. }
  2007. } else {
  2008. return json(['code' => 0, 'msg' => '获取成功', 'data' => [], 'count' => 0]);
  2009. }
  2010. }
  2011. $list = MaterialEvidence::where([['root_id', '=', request()->employee->root_id], ['id', 'in', $share_list]])->field('id,title')->page($param['page'], $param['limit'])->select()->toArray();
  2012. $clue_type = 'materialEvidence';
  2013. $share_type = 'MaterialEvidence';
  2014. foreach ($list as $key => $val) {
  2015. //转发人数
  2016. if (!empty($param['time'])) {
  2017. $newtime = explode(' - ', $param['time']);
  2018. $start_time = $newtime[0] . ' 00:00:00';
  2019. $end_time = $newtime[1] . ' 23:59:59';
  2020. $where[] = ['share_time', 'between', [$start_time, $end_time]];
  2021. $clue_where[] = ['addtime', 'between', [$start_time, $end_time]];
  2022. $foot_where[] = ['addtime', 'between', [$start_time, $end_time]];
  2023. }
  2024. $where[] = ['type', '=', $share_type];
  2025. $where[] = ['employee_id', '=', $empid];
  2026. $where[] = ['data_id', '=', $val['id']];
  2027. $list[$key]['share_count'] = ShareLog::where($where)->count();
  2028. // 获得线索
  2029. $clue_where[] = ['employee_id', '=', $empid];
  2030. $clue_where[] = ['pipe_type', '=', $clue_type];
  2031. $clue_where[] = ['pipe_id', '=', $val['id']];
  2032. $clue_count = CustomerClue::where($clue_where)->count();
  2033. $list[$key]['clue_count'] = $clue_count;
  2034. // 浏览次数
  2035. $foot_where[] = ['employee_id', '=', $empid];
  2036. $foot_where[] = ['pipe_type', '=', $clue_type];
  2037. $foot_where[] = ['reg_info', 'like', '{"id":' . $val['id'] . ',%'];
  2038. $foot_user_count = Footprints::where($foot_where)->field('id,uid')->group('uid')->select();
  2039. $list[$key]['footprints_user_count'] = count($foot_user_count);
  2040. // 浏览时长
  2041. $visit_long = Footprints::where($foot_where)->sum('visit_due_time');
  2042. $list[$key]['visit_long'] = $visit_long;
  2043. $where = [];
  2044. $clue_where = [];
  2045. $foot_where = [];
  2046. }
  2047. $count = MaterialEvidence::where([['root_id', '=', request()->employee->root_id], ['id', 'in', $share_list]])->count();
  2048. //$list = array_slice($list, ($param['page'] - 1) * $param['limit'],$param['limit']);
  2049. return json(['code' => 0, 'msg' => '获取成功', 'data' => $list, 'count' => $count]);
  2050. }
  2051. //计算所有关联员工的视频id
  2052. public function sel_emp_videolist($empid)
  2053. {
  2054. $clue_type = 'materialEvidence';
  2055. $share_type = 'MaterialEvidence';
  2056. $where[] = ['type', '=', $share_type];
  2057. $where[] = ['employee_id', '=', $empid];
  2058. $shared_id = ShareLog::where($where)->group('data_id')->column('data_id');
  2059. $clue_where[] = ['employee_id', '=', $empid];
  2060. $clue_where[] = ['pipe_type', '=', $clue_type];
  2061. $clue_id = CustomerClue::where($clue_where)->group('pipe_id')->column('pipe_id');
  2062. $foot_where[] = ['employee_id', '=', $empid];
  2063. $foot_where[] = ['pipe_type', '=', $clue_type];
  2064. $foot_list = Footprints::where($foot_where)->field('id,pipe_type,reg_info')->select();
  2065. $foot_id = [];
  2066. foreach ($foot_list as $key => $val) {
  2067. $m = $val->getData('reg_info');
  2068. if (!empty($m)) {
  2069. $info = json_decode($m, true);
  2070. $foot_id[] = $info['id'];
  2071. }
  2072. }
  2073. //$clue_id=$foot_id=[];
  2074. $vdid = array_values(array_unique(array_merge($shared_id, $clue_id, $foot_id)));
  2075. return $vdid;
  2076. }
  2077. /**
  2078. * 此方法用于从某个企业复制<拓客案例>至另一个企业
  2079. */
  2080. public function copy_materialcase($from_root_id = 0, $new_root_id = 0)
  2081. {
  2082. if (!$from_root_id || !$new_root_id) return '错误';
  2083. if ($from_root_id == $new_root_id) return '错误';
  2084. $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count();
  2085. if ($company != 2) return '错误';
  2086. //小区
  2087. $communities_arr = [];
  2088. $communities = Community::where('root_id', $from_root_id)->order('addtime')->column('*', 'id');
  2089. foreach ($communities as $comment) {
  2090. $have = Community::where(['root_id' => $new_root_id, 'name' => $comment['name']])->value('id');
  2091. if (!empty($have)) {
  2092. $cid = $have;
  2093. } else {
  2094. $cid = Community::insertGetId([
  2095. 'name' => $comment['name'],
  2096. 'pinyin' => $comment['pinyin'],
  2097. 'nick_name' => $comment['nick_name'],
  2098. 'location' => $comment['location'],
  2099. 'cover_img' => $comment['cover_img'],
  2100. 'desc' => $comment['desc'],
  2101. 'case_num' => $comment['case_num'],
  2102. 'root_id' => $new_root_id,
  2103. 'type' => $comment['type'],
  2104. 'show' => $comment['show'],
  2105. 'initials' => $comment['initials'],
  2106. ]);
  2107. }
  2108. $communities_arr[$comment['id']] = $cid;
  2109. }
  2110. //风格
  2111. $style_arr = [];
  2112. $decostyle = Decostyle::where('root_id', $from_root_id)->order('addtime')->select();
  2113. foreach ($decostyle as $style) {
  2114. $have = Decostyle::where(['root_id' => $new_root_id, 'name' => $style['name']])->value('id');
  2115. if (!empty($have)) {
  2116. $sid = $have;
  2117. } else {
  2118. $sid = Decostyle::insertGetId([
  2119. 'name' => $style['name'],
  2120. 'desc' => $style['desc'],
  2121. 'root_id' => $new_root_id,
  2122. 'type' => $style['type'],
  2123. 'show' => $style['show'],
  2124. ]);
  2125. }
  2126. $style_arr[$style['id']] = $sid;
  2127. }
  2128. //户型
  2129. $housetype_arr = [];
  2130. $housetype = Housetype::where('root_id', $from_root_id)->order('addtime')->select();
  2131. foreach ($housetype as $type) {
  2132. $have = Housetype::where(['root_id' => $new_root_id, 'name' => $type['name']])->value('id');
  2133. if (!empty($have)) {
  2134. $hid = $have;
  2135. } else {
  2136. $hid = Housetype::insertGetId([
  2137. 'name' => $type['name'],
  2138. 'desc' => $type['desc'],
  2139. 'root_id' => $new_root_id,
  2140. 'show' => $type['show'],
  2141. ]);
  2142. }
  2143. $housetype_arr[$type['id']] = $hid;
  2144. }
  2145. $material = MaterialCase::where(['root_id' => $from_root_id, 'del' => 0])->order('addtime')->column('*', 'id');
  2146. foreach ($material as $item) {
  2147. MaterialCase::insertGetId([
  2148. 'root_id' => $new_root_id,
  2149. 'title' => $item['title'],
  2150. 'community_id' => isset($communities_arr[$item['community_id']]) ? $communities_arr[$item['community_id']] : 0,
  2151. 'designer_id' => 0,
  2152. 'style_id' => isset($style_arr[$item['style_id']]) ? $style_arr[$item['style_id']] : 0,
  2153. 'square' => $item['square'],
  2154. 'room' => $item['room'],
  2155. 'hall' => $item['hall'],
  2156. 'toilet' => $item['toilet'],
  2157. 'cover_img' => $item['cover_img'],
  2158. 'desc' => $item['desc'],
  2159. 'publish' => $item['publish'],
  2160. 'housetype_id' => isset($housetype_arr[$item['housetype_id']]) ? $housetype_arr[$item['housetype_id']] : 0,
  2161. 'money' => $item['money'],
  2162. 'img_content' => $item['img_content'],
  2163. 'from' => $item['from'],
  2164. 'qrcode' => $item['qrcode'],
  2165. 'img_content_data' => $item['img_content_data'],
  2166. 'img_download_status' => $item['img_download_status'],
  2167. 'real_case' => $item['real_case'],
  2168. 'video_case' => $item['video_case'],
  2169. 'vr_case' => $item['vr_case'],
  2170. ]);
  2171. }
  2172. return '复制成功';
  2173. }
  2174. /**
  2175. * 此方法用于从某个企业复制<拓客视频>至另一个企业
  2176. */
  2177. public function copy_video($from_root_id = 0, $new_root_id = 0)
  2178. {
  2179. if (!$from_root_id || !$new_root_id) return '错误';
  2180. if ($from_root_id == $new_root_id) return '错误';
  2181. $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count();
  2182. if ($company != 2) return '错误';
  2183. $type_arr = [];
  2184. $label_arr = [];
  2185. $VideoType = VideoType::where(['root_id' => $from_root_id, 'type' => 'video', 'pid' => 0])->select();
  2186. foreach ($VideoType as $val) {
  2187. $typeid = VideoType::insertGetId([
  2188. 'name' => $val['name'],
  2189. 'sort' => $val['sort'],
  2190. 'type' => 'video',
  2191. 'root_id' => $new_root_id,
  2192. 'show' => $val['show'],
  2193. 'pid' => 0
  2194. ]);
  2195. $type_arr[$val['id']] = $typeid;
  2196. $label = VideoType::where(['root_id' => $from_root_id, 'type' => 'video', 'pid' => $val['id']])->select();
  2197. foreach ($label as $la) {
  2198. $labelid = VideoType::insertGetId([
  2199. 'name' => $la['name'],
  2200. 'sort' => $la['sort'],
  2201. 'type' => 'video',
  2202. 'root_id' => $new_root_id,
  2203. 'show' => $la['show'],
  2204. 'pid' => $typeid
  2205. ]);
  2206. $label_arr[$la['id']] = $labelid;
  2207. }
  2208. }
  2209. $video = Video::where(['root_id' => $from_root_id, 'delete_time' => 0])->column('*', 'id');
  2210. foreach ($video as $item) {
  2211. Video::insertGetId([
  2212. 'title' => $item['title'],
  2213. 'description' => $item['description'],
  2214. 'video_url' => $item['video_url'],
  2215. 'type' => isset($type_arr[$item['type']]) ? $type_arr[$item['type']] : 0,
  2216. 'cover' => $item['cover'],
  2217. 'publish' => $item['publish'],
  2218. 'label' => isset($label_arr[$item['label']]) ? $label_arr[$item['label']] : 0,
  2219. 'root_id' => $new_root_id,
  2220. ]);
  2221. }
  2222. return '复制成功';
  2223. }
  2224. /**
  2225. * 此方法用于从某个企业复制<拓客图文>至另一个企业
  2226. */
  2227. public function copy_article($from_root_id = 0, $new_root_id = 0)
  2228. {
  2229. if (!$from_root_id || !$new_root_id) return '错误';
  2230. if ($from_root_id == $new_root_id) return '错误';
  2231. $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count();
  2232. if ($company != 2) return '错误';
  2233. $type_arr = [];
  2234. $label_arr = [];
  2235. $VideoType = VideoType::where(['root_id' => $from_root_id, 'type' => 'article', 'pid' => 0])->select();
  2236. foreach ($VideoType as $val) {
  2237. $typeid = VideoType::insertGetId([
  2238. 'name' => $val['name'],
  2239. 'sort' => $val['sort'],
  2240. 'type' => 'article',
  2241. 'root_id' => $new_root_id,
  2242. 'show' => $val['show'],
  2243. 'pid' => 0
  2244. ]);
  2245. $type_arr[$val['id']] = $typeid;
  2246. $label = VideoType::where(['root_id' => $from_root_id, 'type' => 'article', 'pid' => $val['id']])->select();
  2247. foreach ($label as $la) {
  2248. $labelid = VideoType::insertGetId([
  2249. 'name' => $la['name'],
  2250. 'sort' => $la['sort'],
  2251. 'type' => 'article',
  2252. 'root_id' => $new_root_id,
  2253. 'show' => $la['show'],
  2254. 'pid' => $typeid
  2255. ]);
  2256. $label_arr[$la['id']] = $labelid;
  2257. }
  2258. }
  2259. $Article = Article::where(['root_id' => $from_root_id, 'delete_time' => 0])->column('*', 'id');
  2260. foreach ($Article as $item) {
  2261. $new_label = [];
  2262. $label_old = explode(',', $item['label']);
  2263. if (!empty($label_old)) {
  2264. foreach ($label_old as $v) {
  2265. if (isset($label_arr[$v])) {
  2266. $new_label[] = $label_arr[$v];
  2267. }
  2268. }
  2269. }
  2270. $new_label = implode(',', $new_label);
  2271. Article::insertGetId([
  2272. 'title' => $item['title'],
  2273. 'cover_img' => $item['cover_img'],
  2274. 'type' => isset($type_arr[$item['type']]) ? $type_arr[$item['type']] : 0,
  2275. 'content' => $item['content'],
  2276. 'publish' => $item['publish'],
  2277. 'root_id' => $new_root_id,
  2278. 'label' => $new_label
  2279. ]);
  2280. }
  2281. return '复制成功';
  2282. }
  2283. /**
  2284. * 此方法用于从某个企业复制<公司实力>至另一个企业
  2285. */
  2286. public function copy_companystrength($from_root_id = 0, $new_root_id = 0)
  2287. {
  2288. if (!$from_root_id || !$new_root_id) return '错误';
  2289. if ($from_root_id == $new_root_id) return '错误';
  2290. $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count();
  2291. if ($company != 2) return '错误';
  2292. $cate = CompanyStrengthCate::where(['root_id' => $from_root_id])->select();
  2293. foreach ($cate as $v) {
  2294. CompanyStrengthCate::insertGetId([
  2295. 'root_id' => $new_root_id,
  2296. 'name' => $v['name'],
  2297. 'show' => $v['show'],
  2298. 'pid' => $v['pid'],
  2299. ]);
  2300. }
  2301. $data = CompanyStrength::where(['root_id' => $from_root_id, 'del' => 0])->column('*', 'id');
  2302. foreach ($data as $val) {
  2303. CompanyStrength::insertGetId([
  2304. 'root_id' => $new_root_id,
  2305. 'cate' => $val['cate'],
  2306. 'title' => $val['title'],
  2307. 'media_ids' => $val['media_ids'],
  2308. 'pics' => $val['pics'],
  2309. 'cover' => $val['cover'],
  2310. 'desc' => $val['desc'],
  2311. 'publish' => $val['publish'],
  2312. 'difference' => $val['difference'],
  2313. ]);
  2314. }
  2315. return '复制成功';
  2316. }
  2317. /**
  2318. * 此方法用于从某个企业复制<客户好评>至另一个企业
  2319. */
  2320. public function copy_materialevidence($from_root_id = 0, $new_root_id = 0)
  2321. {
  2322. if (!$from_root_id || !$new_root_id) return '错误';
  2323. if ($from_root_id == $new_root_id) return '错误';
  2324. $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count();
  2325. if ($company != 2) return '错误';
  2326. $data = MaterialEvidence::where(['root_id' => $from_root_id, 'del' => 0])->column('*', 'id');
  2327. foreach ($data as $val) {
  2328. MaterialEvidence::insertGetId([
  2329. 'root_id' => $new_root_id,
  2330. 'cate' => $val['cate'],
  2331. 'title' => $val['title'],
  2332. 'media_ids' => $val['media_ids'],
  2333. 'pics' => $val['pics'],
  2334. 'cover' => $val['cover'],
  2335. 'desc' => $val['desc'],
  2336. 'publish' => $val['publish'],
  2337. 'difference' => $val['difference'],
  2338. ]);
  2339. }
  2340. return '复制成功';
  2341. }
  2342. /**
  2343. * 此方法用于从某个企业复制<热装楼盘>至另一个企业
  2344. * building_id传递只复制单个楼盘
  2345. */
  2346. public function copy_building($from_root_id = 0, $new_root_id = 0, $building_id = 0)
  2347. {
  2348. if (!$from_root_id || !$new_root_id) return '错误';
  2349. if ($from_root_id == $new_root_id) return '错误';
  2350. $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count();
  2351. if ($company != 2) return '错误';
  2352. $where = [
  2353. 'root_id' => $from_root_id,
  2354. 'del' => 0,
  2355. ];
  2356. if (!empty($building_id)) $where['id'] = $building_id;
  2357. Db::startTrans();
  2358. try {
  2359. $data = Building::where($where)->column('*', 'id');
  2360. foreach ($data as $val) {
  2361. //新增小区
  2362. $community = Community::where(['root_id' => $from_root_id, 'id' => $val['community_id']])->find();
  2363. $community_id = Community::where(['root_id' => $new_root_id, 'name' => $community['name']])->value('id');
  2364. if (empty($community_id)) {
  2365. $comm = new Community;
  2366. $comm->name = $community['name'];
  2367. $comm->pinyin = $community['pinyin'];
  2368. $comm->nick_name = $community['nick_name'];
  2369. $comm->location = $community['location'];
  2370. $comm->cover_img = $community['cover_img'];
  2371. $comm->desc = $community['desc'];
  2372. $comm->root_id = $new_root_id;
  2373. $comm->show = $community['show'];
  2374. $comm->initials = $community['initials'];
  2375. $comm->save();
  2376. $community_id = $comm->id;
  2377. }
  2378. $buildingNewId = Building::insertGetId([
  2379. 'name' => $val['name'],
  2380. 'pinyin' => $val['pinyin'],
  2381. 'address' => $val['address'],
  2382. 'duetime' => $val['duetime'],
  2383. 'cover' => $val['cover'],
  2384. 'vr_link' => $val['vr_link'],
  2385. 'content' => $val['content'],
  2386. 'root_id' => $new_root_id,
  2387. 'sign_num' => $val['sign_num'],
  2388. 'start_num' => $val['start_num'],
  2389. 'finish_num' => $val['finish_num'],
  2390. 'from' => $val['from'],
  2391. 'down_status' => $val['down_status'],
  2392. 'media_id' => $val['media_id'],
  2393. 'community_id' => !empty($community_id) ? $community_id : 0,
  2394. ]);
  2395. //楼盘进展
  2396. $progress = BuildingProgress::where(['root_id' => $from_root_id, 'building_id' => $val['id']])->order('addtime')->column('*', 'id');
  2397. foreach ($progress as $p) {
  2398. $pro['building_id'] = $buildingNewId;
  2399. $pro['name'] = $p['name'];
  2400. $pro['type'] = $p['type'];
  2401. $pro['img'] = $p['img'];
  2402. $pro['vr'] = $p['vr'];
  2403. $pro['content'] = $p['content'];
  2404. $pro['root_id'] = $new_root_id;
  2405. $pro['video'] = $p['video'];
  2406. $pro['from'] = $p['from'];
  2407. $pro['down_status'] = $p['down_status'];
  2408. $pro['media_id'] = $p['media_id'];
  2409. BuildingProgress::insert($pro);
  2410. }
  2411. //楼盘户型
  2412. $housetype = BuildingHousetype::where(['root_id' => $from_root_id, 'building_id' => $val['id']])->order('addtime')->select();
  2413. foreach ($housetype as $t) {
  2414. $house['building_id'] = $buildingNewId;
  2415. $house['area'] = $t['area'];
  2416. $house['room'] = $t['room'];
  2417. $house['hall'] = $t['hall'];
  2418. $house['bathroom'] = $t['bathroom'];
  2419. $house['root_id'] = $new_root_id;
  2420. $house['house_img'] = $t['house_img'];
  2421. $house['vr_link'] = $t['vr_link'];
  2422. $house['house_count'] = $t['house_count'];
  2423. $house['orientation'] = $t['orientation'];
  2424. $house['type'] = $t['type'];
  2425. $house['from'] = $t['from'];
  2426. $house['down_status'] = $t['down_status'];
  2427. $house['media_id'] = $t['media_id'];
  2428. $house['img_content'] = $t['img_content'];
  2429. $house['house_img_media_id'] = $t['house_img_media_id'];
  2430. $newHouTypeId = BuildingHousetype::insertGetId($house);
  2431. //研发案例
  2432. $case = BuildingDevelopCase::where(['root_id' => $from_root_id, 'housetype_id' => $t['id']])->order('addtime')->select();
  2433. foreach ($case as $c) {
  2434. $ca['name'] = $c['name'];
  2435. $ca['type'] = $c['type'];
  2436. $ca['vr_link'] = $c['vr_link'];
  2437. $ca['content'] = $c['content'];
  2438. $ca['building_id'] = $buildingNewId;
  2439. $ca['housetype_id'] = $newHouTypeId;
  2440. $ca['root_id'] = $new_root_id;
  2441. $ca['cover'] = $c['cover'];
  2442. $ca['from'] = $c['from'];
  2443. $ca['img_content'] = $c['img_content'];
  2444. $ca['down_status'] = $c['down_status'];
  2445. $ca['media_id'] = $c['media_id'];
  2446. $from_decostyle = Decostyle::where(['root_id' => $from_root_id, 'id' => $c['decostyles_id']])->find();
  2447. $new_decostyle = Decostyle::where(['root_id' => $new_root_id, 'name' => $from_decostyle['name']])->value('id');
  2448. if (empty($new_decostyle)) {
  2449. $ca['decostyles_id'] = Decostyle::insertGetId([
  2450. 'name' => $from_decostyle['name'],
  2451. 'desc' => $from_decostyle['desc'],
  2452. 'root_id' => $new_root_id,
  2453. 'type' => $from_decostyle['type'],
  2454. 'show' => $from_decostyle['show'],
  2455. ]);
  2456. } else {
  2457. $ca['decostyles_id'] = $new_decostyle;
  2458. }
  2459. BuildingDevelopCase::insertGetId($ca);
  2460. }
  2461. }
  2462. }
  2463. Db::commit();
  2464. return '复制成功';
  2465. } catch (\Exception $e) {
  2466. // 回滚事务
  2467. Db::rollback();
  2468. return '复制失败';
  2469. }
  2470. }
  2471. /**
  2472. * 小区导入
  2473. */
  2474. public function importingCommunity()
  2475. {
  2476. return View::fetch();
  2477. }
  2478. /**
  2479. * 导入前日志存储
  2480. */
  2481. public function importCommunityLog()
  2482. {
  2483. $request = request();
  2484. $param = $request->only(['file_name', 'count' => 0]);
  2485. $logData = [
  2486. 'name' => $param['file_name'],
  2487. 'employee_id' => $request->employee->id,
  2488. 'root_id' => $request->employee->root_id,
  2489. 'count' => $param['count']
  2490. ];
  2491. $data = CommunityImportLog::create($logData);
  2492. return json(['code' => 0, 'msg' => '添加成功', 'data' => $data->id]);
  2493. }
  2494. /**
  2495. * 小区excel添加
  2496. */
  2497. public function importCommunityAdd()
  2498. {
  2499. $logId = input('log_id', '', 'intval');
  2500. $log = CommunityImportLog::where('id', $logId)->find();
  2501. if (empty($log)) return json(['code' => 1, 'msg' => '请求错误,记录不存在']);
  2502. $datas = input('content', '', 'trim');
  2503. if (count($datas) == 0) return json(['code' => 1, 'msg' => '请求错误,未传输数据']);
  2504. $rs = ['ok' => 0, 'error' => 0, 'repeat' => 0];
  2505. $root_id = request()->employee->root_id;
  2506. $community = [];
  2507. foreach ($datas as $k => $data) {
  2508. //判断小区是否已存在
  2509. $communityExist = Community::where([['name', '=', $data['name']], ['root_id', '=', $root_id]])->findOrEmpty();
  2510. if (!$communityExist->isEmpty()) {
  2511. $rs['repeat']++;
  2512. } else {
  2513. $one['name'] = $data['name'];
  2514. $one['households'] = $data['households'];
  2515. $one['pinyin'] = hanzi2pinyin($data['name']);
  2516. $one['initials'] = strtoupper(substr($one['pinyin'], 0, 1));
  2517. $one['root_id'] = $root_id;
  2518. $one['employee_id'] = request()->employee->id;
  2519. $one['location'] = $data['province'] . '/' . $data['city'] . '/' . $data['area'];
  2520. $one['duetime'] = $data['duetime'];
  2521. $one['users'] = $data['users'];
  2522. $community[] = $one;
  2523. }
  2524. }
  2525. Db::startTrans();
  2526. try {
  2527. Community::insertAll($community);
  2528. Db::commit();
  2529. } catch (\Exception $e) {
  2530. trace($e->getMessage(), 'error');
  2531. // 回滚事务
  2532. Db::rollback();
  2533. return json(['code' => 1, 'msg' => $e->getMessage()]);
  2534. }
  2535. return json(['code' => 0, 'msg' => '保存成功', 'data' => $rs]);
  2536. }
  2537. /**
  2538. * 导出小区
  2539. */
  2540. public function export_community()
  2541. {
  2542. $request = request();
  2543. $root_id = $request->employee->root_id;
  2544. $list = Community::where([['root_id', '=', $root_id], ['type', '=', 0]])->order(['show' => 'asc', 'id' => 'desc'])->column('name,households,location,duetime,users');
  2545. foreach ($list as $key => $val) {
  2546. $pty = [];
  2547. if (!empty($val['location'])) $pty = explode('/', $val['location']);
  2548. $new[] = ['name' => $val['name'], 'households' => $val['households'], 'province' => !empty($pty[0]) ? $pty[0] : '', 'city' => !empty($pty[1]) ? $pty[1] : '', 'area' => !empty($pty[2]) ? $pty[2] : '', 'duetime' => $val['duetime'], 'users'=> $val['users']];
  2549. }
  2550. $header = ["A1" => "楼盘名称", "B1" => "户数", "C1" => "省", "D1" => "市", "E1" => "区", "F1" => '交房时间', "G1" => '活跃用户'];
  2551. $fileName = date('Y-m-d H:i:s') . '小区导出';
  2552. $this->getExport($header, true, $new, $fileName);
  2553. }
  2554. // 导出
  2555. public function getExport($header = [], $type = false, $data = [], $fileName)
  2556. {
  2557. // 实例化类
  2558. $preadsheet = new Spreadsheet();
  2559. // 创建sheet
  2560. $sheet = $preadsheet->getActiveSheet();
  2561. // 循环设置表头数据
  2562. foreach ($header as $k => $v) {
  2563. $sheet->setCellValue($k, $v);
  2564. }
  2565. // 生成数据
  2566. $sheet->fromArray($data, null, "A2");
  2567. // 样式设置
  2568. $sheet->getDefaultColumnDimension()->setWidth(12);
  2569. // 设置下载与后缀
  2570. if ($type) {
  2571. header("Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  2572. $type = "Xlsx";
  2573. $suffix = "xlsx";
  2574. } else {
  2575. header("Content-Type:application/vnd.ms-excel");
  2576. $type = "Xls";
  2577. $suffix = "xls";
  2578. }
  2579. ob_end_clean(); //清楚缓存区
  2580. // 激活浏览器窗口
  2581. header("Content-Disposition:attachment;filename=$fileName.$suffix");
  2582. //缓存控制
  2583. header("Cache-Control:max-age=0");
  2584. // 调用方法执行下载
  2585. $writer = IOFactory::createWriter($preadsheet, $type);
  2586. // 数据流
  2587. $writer->save("php://output");
  2588. }
  2589. }