Consult.php 124 KB

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