Consult.php 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //竞价单(咨询单)
  10. class Consult extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble =\think\facade\Config::get("noble");
  17. }
  18. public function conlist(){
  19. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  21. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  22. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  23. if ($infoNo !== "") {
  24. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  25. }
  26. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  27. if ($salesman !== "") {
  28. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  29. $where[]= ["b.salesman",'like',"%$salesman%"];
  30. }
  31. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  32. if ($cpName !== "") {
  33. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  34. $where[]= ["a.good_Name",'like',"%$cpName%"];
  35. }
  36. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  37. if ($khNo !== "") {
  38. // $where['khNo'] = $khNo;
  39. $where[]= ["b.khNo",'like',"%$khNo%"];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. // $where['khNo'] = $khNo;
  44. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  45. }
  46. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
  47. if ($relaComNo !== "") $where[]= ['b.companyNo','=',$relaComNo];
  48. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  49. if ($start !="") {
  50. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  51. $where[]= ["a.addtime",'>=',$start];
  52. }
  53. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  54. if($end !=""){
  55. $where[]= ["a.addtime",'<=',$end];
  56. }
  57. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  58. if ($status !== "") {
  59. $where[]= ["a.status",'=',$status];
  60. }
  61. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  62. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  63. // $role=$this->checkRole();
  64. // if(!empty($role['write'])){
  65. // $where[]=["b.createrid","in",$role['write']];
  66. // }
  67. // $role = $this->checkDataShare();
  68. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
  69. $role = $this->checkDataShare();
  70. $hand = resign_hand_user($this->uid,0);
  71. if (!empty($role[DataGroupModel::$type_全部])) {
  72. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  73. $where[] = ['b.createrid', 'in',$arr];
  74. }
  75. // if(!empty($role['platform']) ){
  76. // $where[]=["b.platform_code","in",$role['platform']];
  77. // }
  78. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->count();
  79. $total = ceil($count / $size);
  80. $page = $page >= $total ? $total : $page;
  81. $list = Db::name('consult_info')
  82. ->alias("a")
  83. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  84. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  85. ->where($where)
  86. ->page($page, $size)
  87. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  88. ->order("a.id desc")
  89. ->cursor();
  90. $data=[];
  91. foreach ($list as $value){
  92. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  93. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  94. true):[];
  95. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  96. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  97. $value['khname']="";
  98. if($value['khNo']!==""){
  99. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  100. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  101. }
  102. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  103. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  104. //是否具有编辑权限
  105. $value['is_allow_update'] = 0;
  106. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  107. $data[]=$value;
  108. }
  109. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  110. }
  111. public function info(){
  112. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  113. if($id==""){
  114. return error_show(1002,"咨询单编号不能为空");
  115. }
  116. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  117. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  118. $fo['can']=$in;
  119. if(empty($fo)){
  120. return error_show(1002,"未找到咨询单编号");
  121. }else{
  122. return app_show(0,"获取成功",$fo);
  123. }
  124. }
  125. public function del(){
  126. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  127. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  128. if($de==false){
  129. return error_show(1002,'咨询单信息未找到');
  130. }
  131. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  132. if($dell){
  133. return error_show(0,"删除成功");
  134. }else
  135. return error_show(1002,"删除失败");
  136. }
  137. public function create(){
  138. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  139. if($is_project===""){
  140. return error_show(1002,"参数is_project不能为空");
  141. }
  142. if($is_project==1){
  143. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  144. if($projectNo===""){
  145. return error_show(1002,"参数projectNo不能为空");
  146. }
  147. }
  148. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  149. if($khNo===""){
  150. return error_show(1002,"参数khNo不能为空");
  151. }
  152. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  153. if($companyNo===""){
  154. return error_show(1002,"参数companyNo不能为空");
  155. }
  156. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  157. if($endtime===""){
  158. return error_show(1002,"参数endtime不能为空");
  159. }
  160. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  161. "";
  162. if($platform_code===""){
  163. return error_show(1002,"参数platform_code不能为空");
  164. }
  165. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  166. if($ladder==""){
  167. return error_show(1005,"参数ladder不能为空");
  168. }
  169. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  170. if($token==''){
  171. return error_show(105,"参数token不能为空");
  172. }
  173. $user =GetUserInfo($token);
  174. if(empty($user)||$user['code']!=0){
  175. return error_show(102,"用户数据不存在");
  176. }
  177. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  178. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  179. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  180. $zxNo=makeNo("ZX");
  181. Db::startTrans();
  182. try{
  183. $data=[
  184. "zxNo"=>$zxNo,
  185. "createrid"=>$createrid,
  186. "creater"=>$creater,
  187. "is_project"=>$is_project,
  188. "projectNo"=>isset($projectNo) ? $projectNo:"",
  189. "khNo"=>$khNo,
  190. "companyNo"=>$companyNo,
  191. "endtime"=>$endtime,
  192. "salesman"=>$creater,
  193. "platform_code"=>$platform_code,
  194. "saleid"=>$createrid,
  195. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  196. "status"=>0,
  197. "is_del"=>0,
  198. "addtime"=>date("Y-m-d H:i:s"),
  199. "updatetime"=>date("Y-m-d H:i:s"),
  200. ];
  201. $zx = Db::name("consult_order")->insert($data);
  202. if($zx){
  203. //判断是否是项目,且该项目是否存在台账记录中
  204. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  205. foreach ($ladder as $value){
  206. $infoNo=makeNo("IF");
  207. $specinfo=[];
  208. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  209. foreach ($value["specinfo"] as $v){
  210. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  211. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  212. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  213. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  214. $specinfo[]=$v;
  215. }
  216. }
  217. $info=[
  218. "infoNo"=>$infoNo,
  219. "zxNo"=>$zxNo,
  220. "spuCode"=>"",
  221. "good_name"=>$value['good_name'],
  222. "good_img"=>$value['good_img'],
  223. "cat_id"=>$value['cat_id'],
  224. "unit"=>$value['unit'],
  225. "brand_id"=>$value['brand_id'],
  226. "arrival_time"=>$value['arrival_time'],
  227. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  228. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  229. "is_addrs"=>$value['is_addrs'],
  230. "is_custom"=>$value['is_custom'],
  231. "metal_id"=>$value['metal_id'],
  232. "config"=>isset($value['config'])?$value['config']:"",
  233. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  234. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  235. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  236. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  237. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  238. "budget_price"=>$value['budget_price'],
  239. "num"=>$value['num'],
  240. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  241. "use_desc"=>$value['use_desc'],
  242. "remark"=>$value['remark'],
  243. "status"=>1,
  244. "is_del"=>0,
  245. "addtime"=>date("Y-m-d H:i:s"),
  246. "updatetime"=>date("Y-m-d H:i:s"),
  247. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  248. ];
  249. $up = Db::name("consult_info")->insertGetId($info);
  250. if(!$up){
  251. Db::rollback();
  252. return error_show(1004,'添加失败');
  253. }else{
  254. //修改状态
  255. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  256. "order_code" => $infoNo,//咨询单详情编号
  257. "status" => 1,//这里的status是之前的值
  258. "action_remark" => '',//备注
  259. "action_type" => "create"//新建create,编辑edit,更改状态status
  260. ], "ZXD", 1, $info);
  261. //竞价单不走流程,不推待办已办
  262. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  263. // "order_type" => 'ZXD',
  264. // "order_code" => $infoNo,//咨询单详情编号
  265. // "order_id" => $up,
  266. // "order_status" => 1,
  267. // 'before_status'=>0
  268. // ]);
  269. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  270. if (isset($stand_exists)) {
  271. Db::name('standing_book')
  272. ->where('id', $stand_exists['id'])
  273. ->update([
  274. 'infoNo' => $infoNo,
  275. 'updatetime' => date('Y-m-d H:i:s')
  276. ]);
  277. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  278. } else {
  279. //添加台账信息
  280. Db::name('standing_book')
  281. ->insert([
  282. 'standBookNo' => makeNo("IO"),
  283. 'projectNo' => isset($projectNo) ? $projectNo : '',
  284. 'infoNo' => $infoNo,
  285. 'companyNo' => $companyNo,
  286. 'customer_code' => $khNo,
  287. 'addtime' => date('Y-m-d H:i:s'),
  288. 'updatetime' => date('Y-m-d H:i:s')
  289. ]);
  290. }
  291. }
  292. }
  293. Db::commit();
  294. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  295. }else{
  296. Db::rollback();
  297. return error_show(1004,"新建失败");
  298. }
  299. }catch (\Exception $e){
  300. Db::rollback();
  301. return error_show(1003,$e->getMessage());
  302. }
  303. }
  304. public function zxinfo(){
  305. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  306. if($infoNo==""){
  307. return error_show(1004,"参数infoNo不能为空");
  308. }
  309. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  310. if($zxinfo==false){
  311. return error_show(1004,"未找到信息数据");
  312. }
  313. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  314. if($zxorder==false){
  315. return error_show(1004,"未找到咨询信息数据");
  316. }
  317. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  318. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  319. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  320. $zxinfo['khname']="";
  321. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  322. $zxinfo['khNo']="";
  323. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  324. $zxinfo['brand']="";
  325. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  326. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  327. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  328. $zxinfo['company']="";
  329. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  330. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  331. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  332. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  333. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  334. $zxinfo['project_name']="";
  335. $zxinfo['budget_total']="";
  336. $zxinfo['departinfo']=[];
  337. $zxinfo['unit_name']="";
  338. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  339. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  340. if($zxorder['khNo']!==""){
  341. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  342. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  343. $zxinfo['khNo']= $zxorder['khNo'];
  344. }
  345. if($zxinfo['unit']!==""){
  346. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  347. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  348. }
  349. if($zxinfo['brand_id']!==""){
  350. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  351. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  352. }
  353. if($zxorder['companyNo']!==""){
  354. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  355. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  356. }
  357. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  358. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  359. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  360. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  361. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  362. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  363. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  364. }
  365. if($zxorder['depart']>0){
  366. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  367. }
  368. if($zxorder['platform_code']>0){
  369. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  370. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  371. }
  372. return app_show(0,"获取成功",$zxinfo);
  373. }
  374. public function zxedit(){
  375. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  376. if($infoNo==""){
  377. return error_show(1004,"参数infoNo不能为空");
  378. }
  379. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  380. if($zxinfo==false){
  381. return error_show(1004,"未找到信息数据");
  382. }
  383. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  384. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  385. if($good_name==""){
  386. return error_show(1003,"参数good_name不能为空");
  387. }
  388. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  389. if($good_img==""){
  390. return error_show(1003,"参数good_img不能为空");
  391. }
  392. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  393. if($cat_id==""){
  394. return error_show(1003,"参数cat_id不能为空");
  395. }
  396. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  397. if($unit==""){
  398. return error_show(1003,"参数unit不能为空");
  399. }
  400. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  401. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  402. if($arrival_time==""){
  403. return error_show(1003,"参数arrival_time不能为空");
  404. }
  405. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  406. if($specin==""){
  407. return error_show(1003,"参数specinfo不能为空");
  408. }
  409. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  410. // if($cost_desc==""){
  411. // return error_show(1003,"参数cost_desc不能为空");
  412. // }
  413. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  414. if($is_addrs===""){
  415. return error_show(1003,"参数is_addrs不能为空");
  416. }
  417. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  418. if($is_custom===""){
  419. return error_show(1003,"参数is_custom不能为空");
  420. }
  421. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  422. if($metal_id===""){
  423. return error_show(1003,"参数metal_id不能为空");
  424. }
  425. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  426. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  427. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  428. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  429. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  430. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  431. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  432. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  433. if($num===""){
  434. return error_show(1003,"参数num不能为空");
  435. }
  436. if($budget_price===""){
  437. return error_show(1003,"参数budget_price不能为空");
  438. }
  439. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  440. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  441. if($use_desc==""){
  442. return error_show(1003,"参数use_desc不能为空");
  443. }
  444. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  445. if($remark==""){
  446. return error_show(1003,"参数remark不能为空");
  447. }
  448. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  449. if($endtime==""){
  450. return error_show(1003,"参数endtime不能为空");
  451. }
  452. if($metal_id!=0){
  453. if($config==""){
  454. return error_show(1003,"参数config不能为空");
  455. }
  456. if($other_config==""){
  457. return error_show(1003,"参数other_config不能为空");
  458. }
  459. if($specs_weight===""){
  460. return error_show(1003,"参数specs_weight不能为空");
  461. }
  462. if($gold_price===""){
  463. return error_show(1003,"参数gold_price不能为空");
  464. }
  465. }
  466. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  467. if($token==''){
  468. return error_show(102,"参数token不能为空");
  469. }
  470. $user =GetUserInfo($token);
  471. if(empty($user)||$user['code']!=0){
  472. return error_show(105,"用户数据不存在");
  473. }
  474. $specinfo=[];
  475. foreach ($specin as $v){
  476. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  477. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  478. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  479. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  480. $specinfo[]=$v;
  481. }
  482. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  483. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  484. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  485. Db::startTrans();
  486. try{
  487. $innew =makeNo("IF");
  488. $info=[
  489. "infoNo"=>$innew,
  490. "zxNo"=>$zxinfo['zxNo'],
  491. "spuCode"=>"",
  492. "good_name"=>$good_name,
  493. "good_img"=>$good_img,
  494. "cat_id"=>$cat_id,
  495. "unit"=>$unit,
  496. "brand_id"=>$brand_id,
  497. "arrival_time"=>$arrival_time,
  498. "specinfo"=>json_encode($specinfo),
  499. // "color"=>$color,
  500. // "material"=>$material,
  501. "cost_desc"=>$cost_desc,
  502. "is_addrs"=>$is_addrs,
  503. "is_custom"=>$is_custom,
  504. "metal_id"=>$metal_id,
  505. "config"=>$config,
  506. "other_config"=>$other_config,
  507. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  508. "gold_price"=>$gold_price===""? 0 : $gold_price,
  509. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  510. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  511. "budget_price"=>$budget_price,
  512. "num"=>$num,
  513. "pgNo"=>$pgNo,
  514. "use_desc"=>$use_desc,
  515. "remark"=>$remark,
  516. "bargain_num"=>$zxinfo['bargain_num']+1,
  517. "status"=>1,
  518. "is_del"=>0,
  519. "addtime"=>date("Y-m-d H:i:s"),
  520. "updatetime"=>date("Y-m-d H:i:s"),
  521. 'bargain_status'=>1,
  522. 'enclosure_file'=>$enclosure_file
  523. ];
  524. $up = Db::name("consult_info")->insert($info);
  525. if($up){
  526. //操作记录
  527. ActionLog::logAdd($this->post['token'], [
  528. "order_code" => $innew,//咨询单详情编号
  529. "status" => 1,//这里的status是之前的值
  530. "action_remark" => '',//备注
  531. "action_type" => "edit"//新建create,编辑edit,更改状态status
  532. ], "ZXD", 1, $this->post);
  533. // ProcessOrder::AddProcess($this->post['token'], [
  534. // "order_type" => 'ZXD',
  535. // "order_code" => $innew,//咨询单详情编号
  536. // "order_id" => 0,
  537. // "order_status" => 1
  538. // ]);
  539. if (!empty($bidlist)){
  540. foreach ($bidlist as $value){
  541. unset($value['id']);
  542. $value['infoNo']=$innew;
  543. $value['bidNo']=makeNo("BD");
  544. $value['spuCode']=makeNo("SKU");
  545. $value['status'] =0;
  546. $value['updatetime'] =date("Y-m-d H:i:s");
  547. $in = Db::name("consult_bids")->insert($value);
  548. if($in==false){
  549. Db::rollback();
  550. return error_show(1004,"反馈商品新建失败");
  551. }
  552. ActionLog::logAdd($this->post['token'], [
  553. "order_code" => $innew,//咨询单详情编号
  554. "status" => 1,//这里的status是之前的值
  555. "action_remark" => '',//备注
  556. "action_type" => "edit"//新建create,编辑edit,更改状态status
  557. ], "FKD", 1, $this->post);
  558. }
  559. }
  560. $zxinfo["bargain_status"] =1;
  561. $zxinfo["status"] =6;
  562. $zxinfo["bargain_code"] =$innew;
  563. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  564. $bar=Db::name("consult_info")->save($zxinfo);
  565. if($bar==false){
  566. Db::rollback();
  567. return error_show(1004,"反馈商品更新失败");
  568. }else{
  569. //修改状态,添加待办
  570. ActionLog::logAdd($this->post['token'], [
  571. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  572. "status" => $zxinfo['status'],//这里的status是之前的值
  573. "action_remark" => '',//备注
  574. "action_type" => "edit"//新建create,编辑edit,更改状态status
  575. ], "ZXD", $zxinfo['status'], $zxinfo);
  576. }
  577. //更新consule_order记录
  578. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  579. 'updatetime'=>date('Y-m-d H:i:s')]);
  580. if($op==false){
  581. Db::rollback();
  582. return error_show(1004,'咨询单结束时间更新失败');
  583. }
  584. //维护台账记录
  585. $insert_standing_book_data=[
  586. 'standBookNo'=>makeNo('IO'),
  587. 'infoNo'=>$innew,
  588. 'addtime' => date('Y-m-d H:i:s'),
  589. 'updatetime' => date('Y-m-d H:i:s')
  590. ];
  591. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  592. if(!empty($temp_project)){
  593. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  594. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  595. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  596. }
  597. Db::name('standing_book')->insert($insert_standing_book_data);
  598. Db::commit();
  599. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  600. }
  601. }catch (\Exception $e){
  602. Db::rollback();
  603. return error_show(1004,$e->getMessage());
  604. }
  605. }
  606. //** 发布竞标任务 */
  607. public function bargain(){
  608. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  609. if($infoNo==""){
  610. return error_show(1004,"参数infoNo不能为空");
  611. }
  612. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  613. if($zxinfo==false){
  614. return error_show(1004,"未找到信息数据");
  615. }
  616. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  617. if($status===""){
  618. return error_show(1004,"参数status不能为空");
  619. }
  620. // if($status==1&&$zxinfo['status']>1){
  621. // $zxinfo['bargain_num']=+1;
  622. // }
  623. $old_zxinfo_status = $zxinfo['status'];
  624. $zxinfo['status']=$status;
  625. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  626. $up = Db::name("consult_info")->save($zxinfo);
  627. if($up){
  628. //修改状态,添加待办
  629. ActionLog::logAdd($this->post['token'], [
  630. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  631. "status" => $old_zxinfo_status,//这里的status是之前的值
  632. "action_remark" => '',//备注
  633. "action_type" => "status"//新建create,编辑edit,更改状态status
  634. ], "ZXD", $zxinfo['status'], $zxinfo);
  635. return app_show(0,"状态更新成功");
  636. }else{
  637. return error_show(1003,"状态更新失败");
  638. }
  639. }
  640. //反馈商品添加
  641. public function feadback(){
  642. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  643. if($infoNo==""){
  644. return error_show(1002,"参数infoNo不能为空");
  645. }
  646. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  647. if($zxinfo==false){
  648. return error_show(1003,"未找到信息数据");
  649. }
  650. if($zxinfo['status']!=1){
  651. return error_show(1004,"任务未进行");
  652. }
  653. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  654. if($zx==false){
  655. return error_show(1003,"未找咨询信息数据");
  656. }
  657. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  658. if($pname==""){
  659. return error_show(1002,"参数pname不能为空");
  660. }
  661. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  662. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  663. if($cat_id==""){
  664. return error_show(1002,"参数cat_id不能为空");
  665. }
  666. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  667. if($specin==""){
  668. return error_show(1003,"参数specinfo不能为空");
  669. }
  670. $specinfo=[];
  671. foreach ($specin as $v){
  672. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  673. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  674. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  675. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  676. $specinfo[]=$v;
  677. }
  678. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  679. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  680. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  681. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  682. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  683. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
  684. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  685. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  686. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  687. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  688. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  689. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  690. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  691. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  692. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  693. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  694. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  695. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  696. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  697. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  698. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  699. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  700. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  701. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  702. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  703. if($nake_fee==="" ){
  704. return error_show(1004,"参数nake_fee不能为空");
  705. }
  706. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  707. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  708. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  709. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  710. if($delivery_place==''){
  711. return error_show(1002,"参数delivery_place不能为空");
  712. }
  713. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  714. if($token==''){
  715. return error_show(1002,"参数token不能为空");
  716. }
  717. $user =GetUserInfo($token);
  718. if(empty($user)||$user['code']!=0){
  719. return error_show(1005,"用户数据不存在");
  720. }
  721. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  722. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  723. $bidNo=makeNo("BD");
  724. $spucode=makeNo("SKU");
  725. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  726. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  727. //部分参数的大小校验
  728. $vali = Validate::rule([
  729. 'expire_day|有效时长'=>'require|elt:214748364',
  730. 'delivery_day|物流时长'=>'require|elt:214748364',
  731. 'work_day|生产工期'=>'require|elt:214748364',
  732. 'weight|总重量'=>'require|max:10',
  733. ]);
  734. $temp = [
  735. 'expire_day'=>$expire_day,
  736. 'delivery_day'=>$delivery_day,
  737. 'work_day'=>$work_day,
  738. 'weight'=>$weight,
  739. ];
  740. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  741. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  742. $cat_top_list = made($cat_id);
  743. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  744. if ($is_gold_price == 1 && $cat_top_id == 6) {
  745. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  746. ->find();
  747. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  748. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  749. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  750. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  751. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  752. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  753. $saleprice = $total_fee/ (1 - $budget);
  754. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  755. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  756. }else{
  757. if($nake_fee){
  758. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  759. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  760. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  761. }else{
  762. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  763. (1 - $budget);
  764. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  765. }
  766. }
  767. $supplier = Db::name('supplier')
  768. ->field('id,person,personid')
  769. ->where('code',$supplierNo)
  770. ->findOrEmpty();
  771. $data=[
  772. "bidNo"=>$bidNo,
  773. "infoNo"=>$infoNo,
  774. "zxNo"=>$zxinfo['zxNo'],
  775. "spuCode"=>$spucode,
  776. "good_name"=>$pname,
  777. "brand_id"=>$brandid,
  778. "cat_id"=>$cat_id,
  779. "specinfo"=>json_encode($specinfo),
  780. "unit_id"=>$unit_id,
  781. "cost_desc"=>$cost_desc,
  782. "work_day"=>$work_day,
  783. "delivery_day"=>$delivery_day,
  784. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  785. "expire_day"=>$expire_day,
  786. "origin_place"=>$origin_place,
  787. "supplierNo"=>$supplierNo,
  788. "pay_way"=>$pay_way,
  789. "tax"=>$tax,
  790. "send_way"=>$send_way,
  791. "metal_id"=>$metal_id,
  792. "is_gold_price"=>$is_gold_price,
  793. "config"=>$config,
  794. "other_config"=>$other_config,
  795. "weight"=>$weight,
  796. "good_weight"=>$good_weight,
  797. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  798. "is_diff"=>$is_diff,
  799. "demo_fee"=>$demo_fee,
  800. "delivery_fee"=>$delivery_fee,
  801. "open_fee"=>$open_fee,
  802. "pakge_fee"=>$pakge_fee,
  803. "nake_fee"=>$nake_fee,
  804. "mark_fee"=>$mark_fee,
  805. "cert_fee"=>$cert_fee,
  806. "cost_fee"=>$cost_fee,
  807. "total_fee"=>$total_fee,
  808. "supply_area"=>$supply_area,
  809. "remark"=>$remark,
  810. "sale_price"=>$saleprice,
  811. "sale_cost_fee"=>$sale_cost_fee,
  812. "origin_cost_fee"=>$sale_cost_fee,
  813. "origin_price"=>$saleprice,
  814. "createrid"=>$createrid,
  815. "creater"=>$creater,
  816. "status"=>$zxinfo['status']==1 ?1 :2,
  817. "is_del"=>0,
  818. "addtime"=>date("Y-m-d H:i:s"),
  819. "updatetime"=>date("Y-m-d H:i:s"),
  820. 'delivery_place'=>$delivery_place,//发货地
  821. 'cgder' => $supplier['person'] ?? '',
  822. 'cgderid' => $supplier['personid'] ?? 0,
  823. ];
  824. Db::startTrans();
  825. try{
  826. $insert= Db::name("consult_bids")->insert($data);
  827. if($insert){
  828. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  829. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  830. if($projectinfo==false){
  831. Db::rollback();
  832. return error_show(1006,"未找到项目信息");
  833. }
  834. $temp=[];
  835. $temp['spuCode']=$spucode;
  836. $temp['skuCode']="";
  837. $temp['pgNo']=$zxinfo['pgNo'];
  838. $temp['projectNo']=$zx['projectNo'];
  839. $temp['good_name']=$pname;
  840. $temp['good_type']=$projectinfo['good_type'];
  841. $temp['data_source']=2;
  842. $temp['cat_id']=$cat_id;
  843. $temp['budget_price']=$projectinfo['budget_price'];
  844. $temp['sale_price']=$saleprice;
  845. $temp['origin_price']=$total_fee;
  846. $temp['num']=$zxinfo['num'];
  847. $temp['status']=0;
  848. $temp['is_del']=0;
  849. $temp['creater']=$creater;
  850. $temp['createrid']=$createrid;
  851. $temp['addtime']=date("Y-m-d H:i:s");
  852. $temp['updatetime']=date("Y-m-d H:i:s");
  853. $nu = Db::name("project_feedback")->insert($temp);
  854. if($nu==false){
  855. Db::rollback();
  856. return error_show(1006,"项目反馈失败");
  857. }else{
  858. $old_projectinfo_status = $projectinfo['status'];
  859. $projectinfo['status']=2;
  860. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  861. $up = Db::name("project_info")->save($projectinfo);
  862. if($up){
  863. //修改状态,添加待办,只记录动作
  864. ActionLog::logAdd($this->post['token'], [
  865. "order_code" => $projectinfo['pgNo'],//编码
  866. "status" => $old_projectinfo_status,//这里的status是之前的值
  867. "action_remark" => '',//备注
  868. "action_type" => "status"//新建create,编辑edit,更改状态status
  869. ], "PRI", 2, $projectinfo);
  870. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  871. ->count();
  872. if($count==0){
  873. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  874. if($projetc!=false){
  875. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  876. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  877. if($proc==false){
  878. Db::rollback();
  879. return error_show(1006,"项目反馈失败");
  880. }else{
  881. //修改状态,添加待办
  882. ActionLog::logAdd($this->post['token'], [
  883. "order_code" => $projetc['projectNo'],//项目编码
  884. "status" => 1,//这里的status是之前的值
  885. "action_remark" => '',//备注
  886. "action_type" => "status"//新建create,编辑edit,更改状态status
  887. ], "PRO", 2, $projetc);
  888. ProcessOrder::AddProcess($this->post['token'], [
  889. "order_type" => 'PRO',
  890. "order_code" => $projetc['projectNo'],
  891. "order_id" => $projetc['id'],
  892. "order_status" => 2,"before_status"=>1
  893. ]);
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. Db::commit();
  901. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  902. }else{
  903. Db::rollback();
  904. return error_show(1006,"反馈失败");
  905. }
  906. }catch (\Exception $e){
  907. Db::rollback();
  908. return error_show(1006,$e->getMessage());
  909. }
  910. }
  911. //反馈商品详情
  912. public function feadinfo(){
  913. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  914. if($bidNo==""){
  915. return error_show(1004,"参数bidNo不能为空");
  916. }
  917. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  918. if($info==false){
  919. return error_show(1004,"未找到商品数据");
  920. }
  921. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  922. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  923. $info['cat_info'] = made($info['cat_id'],[]);
  924. $info['noble_weight'] = $info['good_weight'];
  925. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  926. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  927. if($info['brand_id']!=0){
  928. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  929. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  930. }else{
  931. $info["brand_name"]="";
  932. $info["brand_id"]="";
  933. }
  934. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  935. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  936. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  937. $god=[
  938. "metal_id"=>$info['metal_id'],
  939. "weight"=>$info["good_weight"],
  940. "demo_fee"=>$info["demo_fee"],
  941. "delivery_fee"=>$info["delivery_fee"],
  942. "open_fee"=>$info["open_fee"],
  943. "packing_fee"=>$info["pakge_fee"],
  944. "mark_fee"=>$info["mark_fee"],
  945. "nake_fee"=>$info["nake_fee"],
  946. "cert_fee"=>$info["cert_fee"],
  947. "cost_fee"=>$info["cost_fee"],
  948. "num"=>$bidinfo["num"],
  949. ];
  950. if($info['is_gold_price']==1){
  951. $price = GoldPrice($god, $budget/100);
  952. $info['sale_price'] =round($price,2);
  953. }
  954. $info['specinfo'] = json_decode($info['specinfo'],true);
  955. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  956. if($info['delivery_place']!=""){
  957. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  958. }
  959. $info['delivery_place_cn']=GetAddr(json_encode($place));
  960. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  961. if($info['origin_place']!=""){
  962. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  963. }
  964. $info['origin_place_cn']=GetAddr(json_encode($place));
  965. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  966. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  967. $info['bargain'] =$bargain;
  968. $info['good_img'] = explode(',',$info['good_img']);
  969. //添加商品创建人字段
  970. $good_info = Db::name('good_basic')
  971. ->field('id,createrid,creater')
  972. ->where('is_del',0)
  973. ->where('spuCode',$info['spuCode'])
  974. ->findOrEmpty();
  975. $info['good_createrid'] = $good_info['createrid']??0;
  976. $info['good_creater'] = $good_info['creater']??'';
  977. return app_show(0,"获取成功",$info);
  978. }
  979. //反馈商品编辑
  980. public function feededit(){
  981. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  982. if($bidNo==""){
  983. return error_show(1002,"参数bidNo不能为空");
  984. }
  985. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  986. if($bidinfo==false){
  987. return error_show(1003,"未找到信息数据");
  988. }
  989. if($bidinfo['status']>=5){
  990. return error_show(1004,"咨询单已确认无法修改");
  991. }
  992. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  993. if($zxinfo==false){
  994. return error_show(1003,"未找到信息数据");
  995. }
  996. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  997. if($zx==false){
  998. return error_show(1003,"未找咨询信息数据");
  999. }
  1000. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  1001. if($pname==""){
  1002. return error_show(1002,"参数pname不能为空");
  1003. }
  1004. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  1005. // if($brandid==""){
  1006. // return error_show(1002,"参数brandid不能为空");
  1007. // }
  1008. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  1009. if($cat_id==""){
  1010. return error_show(1002,"参数cat_id不能为空");
  1011. }
  1012. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  1013. if($specin==""){
  1014. return error_show(1003,"参数specinfo不能为空");
  1015. }
  1016. $specinfo=[];
  1017. foreach ($specin as $v){
  1018. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  1019. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  1020. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  1021. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  1022. $specinfo[]=$v;
  1023. }
  1024. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  1025. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1026. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1027. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1028. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1029. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1030. :"";
  1031. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1032. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1033. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1034. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1035. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1036. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1037. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1038. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1039. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1040. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1041. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1042. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1043. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1044. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1045. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1046. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1047. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1048. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1049. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1050. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1051. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1052. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1053. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1054. if($delivery_place==''){
  1055. return error_show(1002,"参数delivery_place不能为空");
  1056. }
  1057. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1058. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1059. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1060. $cat_top_list = made($cat_id);
  1061. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1062. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1063. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1064. ->find();
  1065. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1066. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1067. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1068. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1069. $saleprice = $total_fee / (1 - $budget);
  1070. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1071. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1072. }else{
  1073. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1074. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1075. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1076. }
  1077. Db::startTrans();
  1078. try{
  1079. $data=[
  1080. "good_name"=>$pname,
  1081. "brand_id"=>$brandid,
  1082. "cat_id"=>$cat_id,
  1083. "specinfo"=>json_encode($specinfo),
  1084. // "material"=>$material,
  1085. "unit_id"=>$unit_id,
  1086. "cost_desc"=>$cost_desc,
  1087. "work_day"=>$work_day,
  1088. "delivery_day"=>$delivery_day,
  1089. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1090. "expire_day"=>$expire_day,
  1091. "origin_place"=>$origin_place,
  1092. "supplierNo"=>$supplierNo,
  1093. "pay_way"=>$pay_way,
  1094. "tax"=>$tax,
  1095. "send_way"=>$send_way,
  1096. "metal_id"=>$metal_id,
  1097. "is_gold_price"=>$is_gold_price,
  1098. "config"=>$config,
  1099. "other_config"=>$other_config,
  1100. "weight"=>$weight,
  1101. "good_weight"=>$noble_weight,
  1102. "is_diff"=>$is_diff,
  1103. "demo_fee"=>$demo_fee,
  1104. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1105. "delivery_fee"=>$delivery_fee,
  1106. "open_fee"=>$open_fee,
  1107. "pakge_fee"=>$pakge_fee,
  1108. "nake_fee"=>$nake_fee,
  1109. "mark_fee"=>$mark_fee,
  1110. "cert_fee"=>$cert_fee,
  1111. "cost_fee"=>$cost_fee,
  1112. "sale_cost_fee"=>$sale_cost_fee,
  1113. "origin_cost_fee"=>$sale_cost_fee,
  1114. "total_fee"=>$total_fee,
  1115. "sale_price"=>$saleprice,
  1116. "origin_price"=>$saleprice,
  1117. "supply_area"=>$supply_area,
  1118. "remark"=>$remark,
  1119. "status"=>0,
  1120. "updatetime"=>date("Y-m-d H:i:s"),
  1121. 'delivery_place' => $delivery_place
  1122. ];
  1123. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1124. if($insert){
  1125. if($zxinfo['bargain_status']==1){
  1126. $zxinfo['bargain_status']=0;
  1127. $infoip =Db::name("consult_info")->save($zxinfo);
  1128. if($infoip==false){
  1129. Db::rollback();
  1130. return error_show(1006,"咨询信息状态更新失败");
  1131. }
  1132. }
  1133. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1134. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1135. if($projectinfo==false){
  1136. Db::rollback();
  1137. return error_show(1006,"未找到项目信息");
  1138. }
  1139. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1140. if($feed!=false) {
  1141. $feed['good_name']=$pname;
  1142. $feed['good_type']=$projectinfo['good_type'];
  1143. $feed['cat_id']=$cat_id;
  1144. $feed['sale_price']=$saleprice;
  1145. $feed['origin_price']=$total_fee;
  1146. $feed['updatetime']=date("Y-m-d H:i:s");
  1147. $temp['updatetime']=date("Y-m-d H:i:s");
  1148. $nu=Db::name("project_feedback")->save($feed);
  1149. if ($nu == false) {
  1150. Db::rollback();
  1151. return error_show(1006 , "项目反馈失败");
  1152. } else {
  1153. $old_projectinfo_status=$projectinfo['status'];
  1154. $projectinfo['status']=2;
  1155. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1156. $up=Db::name("project_info")->save($projectinfo);
  1157. if ($up) {
  1158. //修改状态,添加待办,只记录动作
  1159. ActionLog::logAdd($this->post['token'] , [
  1160. "order_code"=>$projectinfo['pgNo'] ,//编码
  1161. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1162. "action_remark"=>'' ,//备注
  1163. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1164. ] , "PRI" , 2 , $projectinfo
  1165. );
  1166. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1167. if ($count == 0) {
  1168. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1169. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1170. if ($project_id) {
  1171. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1172. if ($proc == false) {
  1173. Db::rollback();
  1174. return error_show(1006 , "项目反馈失败");
  1175. } else {
  1176. //修改状态,添加待办
  1177. ActionLog::logAdd($this->post['token'] , [
  1178. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1179. "status"=>1 ,//这里的status是之前的值
  1180. "action_remark"=>'' ,//备注
  1181. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1182. ] , "PRO" , 2 , $this->post
  1183. );
  1184. ProcessOrder::AddProcess($this->post['token'] , [
  1185. "order_type"=>'PRO' ,
  1186. "order_code"=>$projectinfo['projectNo'] ,
  1187. "order_id"=>$project_id ,
  1188. "order_status"=>2 , "before_status"=>1
  1189. ]
  1190. );
  1191. }
  1192. }
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. Db::commit();
  1199. return app_show(0,"编辑成功");
  1200. }else{
  1201. Db::rollback();
  1202. return error_show(1004,"编辑失败");
  1203. }
  1204. }catch (\Exception $e){
  1205. Db::rollback();
  1206. return error_show(1004,$e->getMessage());
  1207. }
  1208. }
  1209. //生成议价单
  1210. public function bargain_add(){
  1211. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1212. if($bidNo===""){
  1213. return error_show(1004,"参数bidNo不能为空");
  1214. }
  1215. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1216. if($info==false){
  1217. return error_show(1004,"未找到商品数据");
  1218. }
  1219. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1220. if($consult==false){
  1221. return error_show(1004,"未找到咨询数据");
  1222. }
  1223. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1224. if($bargain_price===""){
  1225. return error_show(1004,"参数bargain_price不能为空");
  1226. }
  1227. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1228. if($info['is_gold_price']==1){
  1229. if($cost_price==""){
  1230. return error_show(1004,"参数cost_price不能为空");
  1231. }
  1232. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1233. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1234. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1235. ->find();
  1236. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1237. }
  1238. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1239. // if($bargain_reason===""){
  1240. // return error_show(1004,"参数bargain_reason不能为空");
  1241. // }
  1242. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1243. if($infos==false){
  1244. return error_show(1004,"未找到商品数据");
  1245. }
  1246. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1247. return error_show(1004,"咨询单招标未结束或已确认商品");
  1248. }
  1249. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1250. if($token==''){
  1251. return error_show(105,"参数token不能为空");
  1252. }
  1253. $user =GetUserInfo($token);
  1254. if(empty($user)||$user['code']!=0){
  1255. return error_show(1002,"用户数据不存在");
  1256. }
  1257. //新增两个字段
  1258. //议价备注
  1259. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1260. //议价原因id
  1261. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1262. if ($result_info_id != '') {
  1263. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1264. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1265. }
  1266. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1267. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1268. $bargainNo =makeNo("BA");
  1269. Db::startTrans();//::todo 金价 毛利计算
  1270. try{
  1271. $data=[
  1272. "bidsNo"=>$bidNo,
  1273. "infoNo"=>$info['infoNo'],
  1274. "zxNo"=>$info['zxNo'],
  1275. "bargainNo"=>$bargainNo,
  1276. "bargain_type"=>1,
  1277. "bargain_reason"=>$bargain_reason,
  1278. "sale_price"=>$info['sale_price'],
  1279. "cost_before_price"=>$info['sale_cost_fee'],
  1280. "cost_after_price"=>$cost_price,
  1281. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1282. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1283. "after_price"=>$bargain_price,
  1284. "exam_info"=>"",
  1285. "status"=>0,
  1286. "is_del"=>0,
  1287. "creater"=>$creater,
  1288. "createrid"=>$createrid,
  1289. "addtime"=>date("Y-m-d H:i:s"),
  1290. "updatetime"=>date("Y-m-d H:i:s"),
  1291. 'bargain_remark'=>$bargain_remark,
  1292. 'result_info_id'=>$result_info_id,
  1293. ];
  1294. $int = Db::name("bargain_order")->insertGetId($data);
  1295. if($int){
  1296. //修改状态,添加待办
  1297. ActionLog::logAdd($this->post['token'], [
  1298. "order_code" => $bargainNo,//咨询单详情编号
  1299. "status" => 0,//这里的status是之前的值
  1300. "action_remark" => '',//备注
  1301. "action_type" => "status"//新建create,编辑edit,更改状态status
  1302. ], "YJD", $data['status'], $data);
  1303. ProcessOrder::AddProcess($this->post['token'], [
  1304. "order_type" => 'YJD',
  1305. "order_code" => $bargainNo,
  1306. "order_id" => $int,
  1307. "order_status" =>0,
  1308. "before_status"=>0,
  1309. 'holder_id'=>$data['createrid']
  1310. ]);
  1311. $odlstatus=$info['status'];
  1312. $info['status']=3;
  1313. $info['updatetime']=date("Y-m-d H:i:s");
  1314. $up =Db::name("consult_bids")->save($info);
  1315. if($up){
  1316. //修改状态,添加待办
  1317. ActionLog::logAdd($this->post['token'], [
  1318. "order_code" => $bidNo,//咨询单详情编号
  1319. "status" => $odlstatus,//这里的status是之前的值
  1320. "action_remark" => '',//备注
  1321. "action_type" => "status"//新建create,编辑edit,更改状态status
  1322. ], "FKD", $info['status'], $info);
  1323. $old_infos_status = $infos['status'];
  1324. $infos['status']=3;
  1325. $infos['updatetime']=date("Y-m-d H:i:s");
  1326. $ups =Db::name("consult_info")->save($infos);
  1327. if($ups){
  1328. //修改状态,添加待办
  1329. ActionLog::logAdd($this->post['token'], [
  1330. "order_code" => $infos['infoNo'],//咨询单详情编号
  1331. "status" => $old_infos_status,//这里的status是之前的值
  1332. "action_remark" => '',//备注
  1333. "action_type" => "status"//新建create,编辑edit,更改状态status
  1334. ], "ZXD", $infos['status'], $infos);
  1335. //维护台账信息
  1336. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1337. Db::commit();
  1338. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1339. }
  1340. }
  1341. }
  1342. Db::rollback();
  1343. return error_show(1004,"议价单新建失败");
  1344. }catch (\Exception $e){
  1345. Db::rollback();
  1346. return error_show(1004,$e->getMessage());
  1347. }
  1348. }
  1349. //选择商品
  1350. public function bids_check(){
  1351. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1352. if($bidNo===""){
  1353. return error_show(1004,"参数bidNo不能为空");
  1354. }
  1355. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1356. if($info==false){
  1357. return error_show(1004,"未找到商品数据");
  1358. }
  1359. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1360. if($infos==false){
  1361. return error_show(1004,"未找到商品数据");
  1362. }
  1363. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1364. return error_show(1004,"咨询单招标未结束或已确认商品");
  1365. }
  1366. Db::startTrans();
  1367. try {
  1368. $oldstattus=$info['status'];
  1369. $info['status']=6;
  1370. $info['updatetime']=date("Y-m-d H:i:s");
  1371. $bids = Db::name("consult_bids")->save($info);
  1372. if($bids){
  1373. //修改状态,添加待办
  1374. ActionLog::logAdd($this->post['token'], [
  1375. "order_code" =>$bidNo,//咨询单详情编号
  1376. "status" => $oldstattus,//这里的status是之前的值
  1377. "action_remark" => '',//备注
  1378. "action_type" => "status"//新建create,编辑edit,更改状态status
  1379. ], "FKD", $info['status'], $info);
  1380. $old_infos_status = $infos['status'];
  1381. $infos['status']=4;
  1382. $infos['updatetime']=date("Y-m-d H:i:s");
  1383. $se = Db::name("consult_info")->save($infos);
  1384. if($se){
  1385. //修改状态,添加待办
  1386. ActionLog::logAdd($this->post['token'], [
  1387. "order_code" => $infos['infoNo'],//咨询单详情编号
  1388. "status" => $old_infos_status,//这里的status是之前的值
  1389. "action_remark" => '',//备注
  1390. "action_type" => "status"//新建create,编辑edit,更改状态status
  1391. ], "ZXD", $infos['status'], $infos);
  1392. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1393. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1394. Db::commit();
  1395. return app_show(0,"商品确定成功");
  1396. }
  1397. }
  1398. Db::rollback();
  1399. return error_show(1004,"商品确认失败");
  1400. }catch (\Exception $e){
  1401. Db::rollback();
  1402. return error_show(1004,$e->getMessage());
  1403. }
  1404. }
  1405. //议价审核
  1406. /**
  1407. * status:
  1408. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1409. */
  1410. public function bargain_status(){
  1411. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1412. if($bargainNo===""){
  1413. return error_show(1004,"参数bargainNo不能为空");
  1414. }
  1415. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1416. if($info==false){
  1417. return error_show(1004,"未找到议价数据");
  1418. }
  1419. if($info['status']==12){
  1420. return error_show(1004,"议价单已取消");
  1421. }
  1422. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1423. if($bids==false){
  1424. return error_show(1004,"未找到商品数据");
  1425. }
  1426. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1427. if($coninfo==false){
  1428. return error_show(1004,"未找到咨询单数据");
  1429. }
  1430. if($bids['status']==6){
  1431. return error_show(1004,"咨询已选择商品");
  1432. }
  1433. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1434. if($status===''){
  1435. return error_show(1005,"参数status不能为空");
  1436. }
  1437. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1438. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1439. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1440. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1441. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1442. if($bids['is_gold_price']==1){
  1443. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1444. ->find();
  1445. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1446. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1447. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1448. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1449. $saleprice =$total_fe / (1 - $budget);
  1450. $rate_price = $total_fe / (1 - $rate);
  1451. $money_price =$total_fe / (1 - $money_rate);
  1452. $lower_price =$total_fe / (1 - $lower_rate);
  1453. }else{
  1454. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1455. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1456. if($bids['nake_fee']!=0){
  1457. $saleprice = ($total_fe)/ (1 - $budget);
  1458. $rate_price = ($total_fe)/ (1 - $rate);
  1459. $money_price =($total_fe)/ (1 - $money_rate);
  1460. $lower_price = ($total_fe) / (1 - $lower_rate);
  1461. }else{
  1462. $saleprice = $total_fe / (1 - $budget);
  1463. $rate_price =$total_fe/ (1 - $rate);
  1464. $money_price =$total_fe / (1 - $money_rate);
  1465. $lower_price = $total_fe/ (1 - $lower_rate);
  1466. }
  1467. }
  1468. $ra_status = $info['status'];
  1469. if($status==1){
  1470. if($info['status']==0){
  1471. if($info['after_price']<$rate_price){
  1472. $info['status']=2;
  1473. }else{
  1474. $info['status']=1;
  1475. }
  1476. }elseif($info['status']==2){
  1477. $info['status']=4;
  1478. }elseif($info['status']==4||$info['status']==5){
  1479. if($info['after_price']<$money_price){
  1480. $info['status']=7;
  1481. }else{
  1482. $info['status']=6;
  1483. }
  1484. }elseif($info['status']==7){
  1485. $info['lower_price'] =$lower_price;
  1486. if($info['after_price']<$lower_price){
  1487. $info['status']=10;
  1488. }else{
  1489. $info['status']=9;
  1490. }
  1491. }
  1492. }else{
  1493. if($info['status']==0){
  1494. $info['status']=3;
  1495. }elseif($info['status']==2){
  1496. $info['status']=4;
  1497. }elseif($info['status']==4||$info['status']==5){
  1498. $info['status']=8;
  1499. }elseif($info['status']==7){
  1500. $info['lower_price'] =$lower_price;
  1501. $info['status']=11;
  1502. }
  1503. }
  1504. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1505. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1506. if($token==''){
  1507. return error_show(105,"参数token不能为空");
  1508. }
  1509. $user =GetUserInfo($token);
  1510. if(empty($user)||$user['code']!=0){
  1511. return error_show(1002,"用户数据不存在");
  1512. }
  1513. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1514. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1515. Db::startTrans();
  1516. try{
  1517. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1518. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1519. "creater"=>$creater];
  1520. // $info['status'] =$status;
  1521. $info['remark'] =$remark;
  1522. $info['exam_info']=json_encode($examinfo) ;
  1523. $info['updatetime'] =date("Y-m-d H:i:s");
  1524. $up =Db::name("bargain_order")->save($info);
  1525. if($up){
  1526. //修改状态,添加待办
  1527. ActionLog::logAdd($this->post['token'], [
  1528. "order_code" => $bargainNo,//咨询单详情编号
  1529. "status" =>$ra_status,//这里的status是之前的值
  1530. "action_remark" => '',//备注
  1531. "action_type" => "status"//新建create,编辑edit,更改状态status
  1532. ], "YJD", $info['status'], $info);
  1533. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
  1534. ProcessOrder::AddProcess($token,$process);
  1535. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1536. $bidstatus=$bids['status'];
  1537. $bids['status']=5;
  1538. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1539. $bids['sale_price']=$info['after_price'];
  1540. if($bids['is_gold_price']==1){
  1541. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1542. // ->find();
  1543. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1544. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1545. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1546. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1547. }
  1548. }
  1549. $bids['updatetime']=date("Y-m-d H:i:s");
  1550. $up =Db::name("consult_bids")->save($bids);
  1551. if($up==false){
  1552. Db::rollback();
  1553. return error_show(1004,"数据更新失败");
  1554. }
  1555. ActionLog::logAdd($this->post['token'], [
  1556. "order_code" => $info["bidsNo"],//咨询单详情编号
  1557. "status" => $bidstatus,//这里的status是之前的值
  1558. "action_remark" => '',//备注
  1559. "action_type" => "status"//新建create,编辑edit,更改状态status
  1560. ], "FKD", $bids['status'], $bids);
  1561. }
  1562. Db::commit();
  1563. return app_show(0,"更新成功");
  1564. }
  1565. }catch (\Exception $e){
  1566. Db::rollback();
  1567. return error_show(1004,$e->getMessage());
  1568. }
  1569. }
  1570. public function bargain_info(){
  1571. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1572. if($bargainNo===""){
  1573. return error_show(1004,"参数bargainNo不能为空");
  1574. }
  1575. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1576. if($info==false){
  1577. return error_show(1004,"未找到议价数据");
  1578. }
  1579. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1580. if($bidinfos==false){
  1581. return error_show(1004,"未找到商品数据");
  1582. }
  1583. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1584. if($consultinfos==false){
  1585. return error_show(1004,"未找到咨询商品数据");
  1586. }
  1587. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1588. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1589. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1590. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1591. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1592. $info['before_rate'] =round($info['before_rate']*100,2);
  1593. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1594. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1595. $info['after_rate'] = round($info['after_rate']*100,2);
  1596. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1597. if($bidinfos['brand_id']!=0){
  1598. $info['brand_id'] = $bidinfos['brand_id'];
  1599. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1600. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1601. }else{
  1602. $info["brand_name"]="";
  1603. $info["brand_id"]="";
  1604. }
  1605. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1606. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1607. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1608. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1609. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1610. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1611. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1612. $info['budget'] =$budget;
  1613. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1614. if($info['after_rate']>=$catinfo['rate']){
  1615. //业务主管利率
  1616. $info['rate_status'] =1;
  1617. }
  1618. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1619. //财务主管利率
  1620. $info['rate_status'] =2;
  1621. }
  1622. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1623. //boss利率
  1624. $info['rate_status'] =3;
  1625. }
  1626. $god=[
  1627. "metal_id"=>$bidinfos['metal_id'],
  1628. "weight"=>$bidinfos["good_weight"],
  1629. "demo_fee"=>$bidinfos["demo_fee"],
  1630. "delivery_fee"=>$bidinfos["delivery_fee"],
  1631. "open_fee"=>$bidinfos["open_fee"],
  1632. "packing_fee"=>$bidinfos["pakge_fee"],
  1633. "mark_fee"=>$bidinfos["mark_fee"],
  1634. "nake_fee"=>$bidinfos["nake_fee"],
  1635. "cert_fee"=>$bidinfos["cert_fee"],
  1636. "cost_fee"=>$bidinfos["cost_fee"],
  1637. "num"=>$bidinfoe["num"],
  1638. ];
  1639. $info['gold_price']=0;
  1640. $info['noble_weight']=$bidinfos['good_weight'];
  1641. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1642. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1643. ->find();
  1644. $info['gold_price'] =$gold['price'];
  1645. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1646. }else{
  1647. if($bidinfos['nake_fee']!=0){
  1648. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1649. }else{
  1650. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1651. }
  1652. }
  1653. $info['cost_desc'] =$bidinfos['cost_desc'];
  1654. $info['work_day'] =$bidinfos['work_day'];
  1655. $info['delivery_day'] =$bidinfos['delivery_day'];
  1656. $info['expire_day'] =$bidinfos['expire_day'];
  1657. $info['origin_place'] =$bidinfos['origin_place'];
  1658. $info['origin_addr'] ="";
  1659. if($bidinfos['origin_place']!=''){
  1660. $code = explode(",",$bidinfos['origin_place']);
  1661. $temp=[];
  1662. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1663. $temp['city_code']=isset($code[1])?$code[1]:"";
  1664. $temp['area_code']=isset($code[2])?$code[2]:"";
  1665. $addr= GetAddr(json_encode($temp));
  1666. $info['origin_addr'] = $addr;
  1667. }
  1668. $info['supplierNo'] =$bidinfos['supplierNo'];
  1669. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1670. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1671. $info['pay_way'] =$bidinfos['pay_way'];
  1672. $info['tax'] =$bidinfos['tax'];
  1673. $info['send_way'] =$bidinfos['send_way'];
  1674. $info['metal_id'] =$bidinfos['metal_id'];
  1675. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1676. $info['config'] =$bidinfos['config'];
  1677. $info['other_config'] =$bidinfos['other_config'];
  1678. $info['weight'] =$bidinfos['weight'];
  1679. $info['good_weight'] =$bidinfos['good_weight'];
  1680. $info['is_diff'] =$bidinfos['is_diff'];
  1681. $info['demo_fee'] =$bidinfos['demo_fee'];
  1682. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1683. $info['open_fee'] =$bidinfos['open_fee'];
  1684. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1685. $info['nake_fee'] =$bidinfos['nake_fee'];
  1686. $info['mark_fee'] =$bidinfos['mark_fee'];
  1687. $info['cert_fee'] =$bidinfos['cert_fee'];
  1688. $info['cost_fee'] =$bidinfos['cost_fee'];
  1689. $info['total_fee'] =$bidinfos['total_fee'];
  1690. $info['supply_area'] =$bidinfos['supply_area'];
  1691. $info['remark'] =$bidinfos['remark'];
  1692. $info['is_addrs'] =$consultinfos['is_addrs'];
  1693. $info['is_custom'] =$consultinfos['is_custom'];
  1694. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1695. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1696. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1697. if($info['status']==7){
  1698. $info['lower_price'] =round($lower_price,2);
  1699. }
  1700. //获取议价原因
  1701. if ($info['result_info_id'] != 0) {
  1702. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1703. } else {
  1704. $info['result_info'] = '';
  1705. }
  1706. return app_show(0,"获取成功",$info);
  1707. }
  1708. public function bidlist(){
  1709. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1710. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1711. $where=[['is_del',"=",0]];
  1712. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1713. if ($zxNo !== "") {
  1714. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1715. }
  1716. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1717. if ($infoNo !== "") {
  1718. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1719. }
  1720. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1721. if ($bidNo !== "") {
  1722. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1723. }
  1724. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1725. if ($pgNo !== "") {
  1726. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1727. $where[] = ['infoNo','in',$bidinfo];
  1728. }
  1729. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1730. if ($bargain_status !== "") {
  1731. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1732. $where[] = ['infoNo','in',$bidinfo];
  1733. }
  1734. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1735. if ($projectNo !== "") {
  1736. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1737. ("zxNo");
  1738. $where[] = ['zxNo','in',$zxlist];
  1739. }
  1740. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1741. if($is_own==1){
  1742. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1743. if($token==""){
  1744. return error_show(101,'token不能为空');
  1745. }
  1746. $apply_id =GetUserInfo($token);
  1747. if(empty($apply_id)||$apply_id['code']!=0){
  1748. return error_show(1002,"申请人数据不存在");
  1749. }
  1750. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1751. $where[]=['createrid',"=",$rm];
  1752. }
  1753. $count = Db::name('consult_bids')->where($where)->count();
  1754. $total = ceil($count / $size);
  1755. $page = $page >= $total ? $total : $page;
  1756. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1757. $data=[];
  1758. foreach ($list as $value){
  1759. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1760. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1761. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1762. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1763. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1764. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1765. if($value['brand_id']!=0){
  1766. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1767. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1768. }else{
  1769. $value["brand_name"]="";
  1770. $value["brand_id"]="";
  1771. }
  1772. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1773. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1774. $god=[
  1775. "metal_id"=>$value['metal_id'],
  1776. "weight"=>$value["good_weight"],
  1777. "demo_fee"=>$value["demo_fee"],
  1778. "delivery_fee"=>$value["delivery_fee"],
  1779. "open_fee"=>$value["open_fee"],
  1780. "packing_fee"=>$value["pakge_fee"],
  1781. "mark_fee"=>$value["mark_fee"],
  1782. "nake_fee"=>$value["nake_fee"],
  1783. "cert_fee"=>$value["cert_fee"],
  1784. // "cost_fee"=>$value["cost_fee"],
  1785. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1786. //暂时注掉,搞不清楚原因@吴广广
  1787. "num"=>$bidinfo["num"],
  1788. ];
  1789. $top_cat = made($value['cat_id']);
  1790. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1791. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1792. $price = GoldPrice($god, $budget/100);
  1793. $value['sale_price'] = round($price,2);
  1794. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1795. $value["origin_price"];
  1796. }
  1797. $value['cost_fee'] =$value['origin_cost_fee'];
  1798. $value['specinfo'] = json_decode($value['specinfo'],true);
  1799. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1800. $value['bargain_status']=$bidinfo['bargain_status'];
  1801. //reject驳回原因,status==5表示驳回
  1802. $value['reject']=[];
  1803. if ($value['status'] >=5) {
  1804. $value['reject'] = Db::name('bargain_order')
  1805. ->field('id,remark,status')
  1806. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1807. ->whereIn('status', [3,8,11])->order("id desc")
  1808. ->find();
  1809. }
  1810. //产地
  1811. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1812. if($value['delivery_place']!=""){
  1813. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1814. }
  1815. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1816. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1817. if($value['origin_place']!=""){
  1818. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1819. }
  1820. $value['origin_addr']=GetAddr(json_encode($place));
  1821. // if($value['origin_place']!=''){
  1822. // $code = explode(",",$value['origin_place']);
  1823. // $temp=[];
  1824. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1825. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1826. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1827. // $addr= GetAddr(json_encode($temp));
  1828. // $value['origin_addr'] = $addr;
  1829. // }
  1830. $good_info = Db::name('good_basic')
  1831. ->field('id,createrid,creater')
  1832. ->where('is_del',0)
  1833. ->where('spuCode',$value['spuCode'])
  1834. ->findOrEmpty();
  1835. $value['good_createrid']=$good_info['createrid']??$value['createrid'];
  1836. $value['good_creater']=$good_info['creater']??$value['creater'];
  1837. $data[] = $value;
  1838. }
  1839. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1840. }
  1841. public function feedlist(){
  1842. $where=[['is_del',"=",0]];
  1843. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1844. if ($zxNo !== "") {
  1845. $where[] = ['zxNo','=',$zxNo];
  1846. }
  1847. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1848. if ($infoNo !== "") {
  1849. $where[] = ['infoNo','=',$infoNo];
  1850. }
  1851. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1852. if ($bidNo !== "") {
  1853. $where[] = ['bidNo','=',$bidNo];
  1854. }
  1855. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1856. if ($projectNo !== "") {
  1857. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1858. ("zxNo");
  1859. $where[] = ['zxNo','in',$zxlist];
  1860. }
  1861. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1862. if($token==''){
  1863. return error_show(102,"参数token不能为空");
  1864. }
  1865. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1866. if($is_own==1){
  1867. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1868. if($token==""){
  1869. return error_show(101,'token不能为空');
  1870. }
  1871. $apply_id =GetUserInfo($token);
  1872. if(empty($apply_id)||$apply_id['code']!=0){
  1873. return error_show(1002,"申请人数据不存在");
  1874. }
  1875. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1876. $where[]=['createrid',"=",$rm];
  1877. }
  1878. $list =Db::name('consult_bids')->where($where)->select();
  1879. $data=[];
  1880. foreach ($list as $value){
  1881. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1882. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1883. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1884. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1885. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1886. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1887. if($value['brand_id']!=0){
  1888. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1889. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1890. }else{
  1891. $value["brand_name"]="";
  1892. $value["brand_id"]="";
  1893. }
  1894. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1895. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1896. $god=[
  1897. "metal_id"=>$value['metal_id'],
  1898. "weight"=>$value["good_weight"],
  1899. "demo_fee"=>$value["demo_fee"],
  1900. "delivery_fee"=>$value["delivery_fee"],
  1901. "open_fee"=>$value["open_fee"],
  1902. "packing_fee"=>$value["pakge_fee"],
  1903. "mark_fee"=>$value["mark_fee"],
  1904. "nake_fee"=>$value["nake_fee"],
  1905. "cert_fee"=>$value["cert_fee"],
  1906. "cost_fee"=>$value["cost_fee"],
  1907. "num"=>$bidinfo["num"],
  1908. ];
  1909. if ($value['is_gold_price'] == 1 ) {
  1910. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1911. ->find();
  1912. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1913. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1914. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1915. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1916. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1917. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1918. }else{
  1919. if($value["nake_fee"]){
  1920. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1921. }else{
  1922. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1923. (1 - $budget);
  1924. }
  1925. }
  1926. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1927. $value['specinfo'] = json_decode($value['specinfo'],true);
  1928. $value['bargain_status']=$bidinfo['bargain_status'];
  1929. $data[]=$value;
  1930. }
  1931. return app_show(0,"获取成功",$data);
  1932. }
  1933. public function bragain_list(){
  1934. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1935. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1936. $where=[['bo.is_del',"=",0]];
  1937. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1938. if($bidsNo!=""){
  1939. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1940. }
  1941. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1942. if ($zxNo !== "") {
  1943. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1944. }
  1945. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1946. if ($bargainNo !== "") {
  1947. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1948. }
  1949. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1950. if ($status!== "") {
  1951. $where[] = ['bo.status','=',$status];
  1952. }
  1953. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1954. if ($infoNo !== "") {
  1955. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1956. }
  1957. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1958. if ($projectNo !== "") {
  1959. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column("zxNo");
  1960. $where[] = ['bo.zxNo','in',$zxlist];
  1961. }
  1962. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1963. if ($pgNo !== "") {
  1964. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1965. $where[] = ['bo.infoNo','in',$bidinfo];
  1966. }
  1967. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1968. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1969. if($start!=""){
  1970. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1971. }
  1972. if($end!=""){
  1973. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1974. }
  1975. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1976. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1977. // $role=$this->checkRole();
  1978. // if(!empty($role['write'])){
  1979. // $where[]=["bo.createrid","in",$role['write']];
  1980. // }
  1981. // $role = $this->checkDataShare();
  1982. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
  1983. $role = $this->checkDataShare();
  1984. $hand = resign_hand_user($this->uid,0);
  1985. if (!empty($role[DataGroupModel::$type_全部])) {
  1986. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  1987. $where[] = ['bo.createrid', 'in',$arr];
  1988. }
  1989. $count=Db::name("bargain_order")
  1990. ->alias('bo')
  1991. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1992. ->where($where)
  1993. ->count();
  1994. $total = ceil($count / $size);
  1995. $page = $page >= $total ? $total : $page;
  1996. $list = Db::name('bargain_order')
  1997. ->alias('bo')
  1998. ->field('bo.*,u.itemid')
  1999. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  2000. ->where($where)
  2001. ->page($page, $size)
  2002. ->order('bo.addtime', 'desc')
  2003. ->cursor();
  2004. $data=[];
  2005. foreach ($list as $value){
  2006. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  2007. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  2008. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  2009. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  2010. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  2011. if($bidinfos['brand_id']!=0){
  2012. $value['brand_id'] = $bidinfos['brand_id'];
  2013. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  2014. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2015. }else{
  2016. $value["brand_name"]="";
  2017. $value["brand_id"]="";
  2018. }
  2019. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  2020. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  2021. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  2022. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2023. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  2024. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  2025. $value['budget'] =$budget;
  2026. $god=[
  2027. "metal_id"=>$bidinfos['metal_id'],
  2028. "weight"=>$bidinfos["good_weight"],
  2029. "demo_fee"=>$bidinfos["demo_fee"],
  2030. "delivery_fee"=>$bidinfos["delivery_fee"],
  2031. "open_fee"=>$bidinfos["open_fee"],
  2032. "packing_fee"=>$bidinfos["pakge_fee"],
  2033. "mark_fee"=>$bidinfos["mark_fee"],
  2034. "nake_fee"=>$bidinfos["nake_fee"],
  2035. "cert_fee"=>$bidinfos["cert_fee"],
  2036. "cost_fee"=>$bidinfos["cost_fee"],
  2037. "num"=>$bidinfoe["num"],
  2038. ];
  2039. // if($bidinfos['is_gold_price']==1){
  2040. // $price = GoldPrice($god, $budget/100);
  2041. // }else{
  2042. // $price = GoodPrice($god, $budget/100);
  2043. // }
  2044. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  2045. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2046. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2047. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2048. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2049. //是否具有编辑权限
  2050. $value['is_allow_update'] = 0;
  2051. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2052. $data[]=$value;
  2053. }
  2054. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2055. }
  2056. public function crontablist(){
  2057. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2058. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2059. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2060. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2061. if ($zxNo !== "") {
  2062. $where[] = ['a.zxNo','=',$zxNo];
  2063. }
  2064. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2065. if ($salesman !== "") {
  2066. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2067. $where[]= ["b.salesman",'like',"%$salesman%"];
  2068. }
  2069. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2070. if ($cpName !== "") {
  2071. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2072. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2073. }
  2074. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2075. if ($khNo !== "") {
  2076. // $where['khNo'] = $khNo;
  2077. $where[]= ["b.khNo",'like',"%$khNo%"];
  2078. }
  2079. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2080. if ($start !="") {
  2081. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2082. $where[]= ["a.addtime",'>=',$start];
  2083. }
  2084. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2085. if($end !=""){
  2086. $where[]= ["a.addtime",'<=',$end];
  2087. }
  2088. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2089. if ($status !== "") {
  2090. $where[]= ["a.status",'=',$status];
  2091. }
  2092. //查看非本公司的竞价单
  2093. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  2094. if($relaComNo!="") $where[]=['b.companyNo','<>', $relaComNo];
  2095. // $role=$this->checkRole();
  2096. // if(!empty($role['platform']) ){
  2097. // $where[]=["b.platform_code","in",$role['platform']];
  2098. // }
  2099. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2100. ->count();
  2101. $total = ceil($count / $size);
  2102. $page = $page >= $total ? $total : $page;
  2103. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2104. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2105. $data=[];
  2106. foreach ($list as $value){
  2107. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2108. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2109. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2110. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2111. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2112. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2113. $value['khname']="";
  2114. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2115. true):[];
  2116. if($value['khNo']!==""){
  2117. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2118. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2119. }
  2120. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2121. ->find();
  2122. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2123. $value['is_feed'] =$consult==false?0:1;
  2124. $value['is_all_feed'] =$consults==false?0:1;
  2125. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2126. $data[]=$value;
  2127. }
  2128. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2129. }
  2130. //复制上面的bidlist方法,只更改排序方式
  2131. public function bidlistCopy()
  2132. {
  2133. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2134. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2135. $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
  2136. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2137. if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2138. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2139. if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2140. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2141. if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2142. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2143. if ($pgNo !== "") {
  2144. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2145. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2146. }
  2147. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2148. if ($bargain_status !== "") {
  2149. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2150. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2151. }
  2152. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2153. if ($projectNo !== "") {
  2154. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  2155. $where[] = ['cb.zxNo', 'in', $zxlist];
  2156. }
  2157. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2158. if ($is_own == 1) {
  2159. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2160. if ($token == "") return error_show(101, 'token不能为空');
  2161. $apply_id = GetUserInfo($token);
  2162. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2163. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2164. $where[] = ['cb.createrid', "=", $rm];
  2165. }
  2166. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2167. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2168. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2169. if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
  2170. $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
  2171. if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
  2172. $count = Db::name('consult_bids')
  2173. ->alias('cb')
  2174. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2175. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2176. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2177. ->where($where)
  2178. ->count();
  2179. $total = ceil($count / $size);
  2180. $page = $page >= $total ? $total : $page;
  2181. $list = Db::name('consult_bids')
  2182. ->alias('cb')
  2183. ->field('cb.*,u.itemid,s.name supplierName')
  2184. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2185. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2186. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2187. ->where($where)
  2188. ->page($page, $size)
  2189. ->order('cb.addtime', 'desc')
  2190. ->cursor();
  2191. $data = [];
  2192. foreach ($list as $value) {
  2193. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2194. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2195. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2196. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2197. // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2198. // $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2199. if ($value['brand_id'] != 0) {
  2200. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2201. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2202. } else {
  2203. $value["brand_name"] = "";
  2204. $value["brand_id"] = "";
  2205. }
  2206. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2207. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2208. $god = [
  2209. "metal_id" => $value['metal_id'],
  2210. "weight" => $value["good_weight"],
  2211. "demo_fee" => $value["demo_fee"],
  2212. "delivery_fee" => $value["delivery_fee"],
  2213. "open_fee" => $value["open_fee"],
  2214. "packing_fee" => $value["pakge_fee"],
  2215. "mark_fee" => $value["mark_fee"],
  2216. "nake_fee" => $value["nake_fee"],
  2217. "cert_fee" => $value["cert_fee"],
  2218. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2219. "num" => $bidinfo["num"],
  2220. ];
  2221. if ($value['is_gold_price'] == 1) {
  2222. $price = GoldPrice($god, $budget / 100);
  2223. $value['sale_price'] = round($price, 2);
  2224. }
  2225. $value['cost_fee'] = $value['origin_cost_fee'];
  2226. $value['specinfo'] = json_decode($value['specinfo'], true);
  2227. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2228. $value['bargain_status'] = $bidinfo['bargain_status'];
  2229. //reject驳回原因,status==5表示驳回
  2230. $value['reject'] = [];
  2231. if ($value['status'] >= 5) {
  2232. $value['reject'] = Db::name('bargain_order')
  2233. ->field('id,remark,status')
  2234. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2235. ->whereIn('status', [3, 8, 11])->order("id desc")
  2236. ->find();
  2237. }
  2238. //产地
  2239. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2240. if ($value['delivery_place'] != "") {
  2241. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2242. }
  2243. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2244. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2245. if ($value['origin_place'] != "") {
  2246. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2247. }
  2248. $value['origin_addr'] = GetAddr(json_encode($place));
  2249. // if($value['origin_place']!=''){
  2250. // $code = explode(",",$value['origin_place']);
  2251. // $temp=[];
  2252. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2253. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2254. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2255. // $addr= GetAddr(json_encode($temp));
  2256. // $value['origin_addr'] = $addr;
  2257. // }
  2258. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2259. $data[] = $value;
  2260. }
  2261. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2262. }
  2263. }